routes.rb 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. # frozen_string_literal: true
  2. require 'sidekiq_unique_jobs/web'
  3. require 'sidekiq-scheduler/web'
  4. Sidekiq::Web.set :session_secret, Rails.application.secrets[:secret_key_base]
  5. Rails.application.routes.draw do
  6. root 'home#index'
  7. mount LetterOpenerWeb::Engine, at: 'letter_opener' if Rails.env.development?
  8. health_check_routes
  9. authenticate :user, lambda { |u| u.admin? } do
  10. mount Sidekiq::Web, at: 'sidekiq', as: :sidekiq
  11. mount PgHero::Engine, at: 'pghero', as: :pghero
  12. end
  13. use_doorkeeper do
  14. controllers authorizations: 'oauth/authorizations',
  15. authorized_applications: 'oauth/authorized_applications',
  16. tokens: 'oauth/tokens'
  17. end
  18. get '.well-known/host-meta', to: 'well_known/host_meta#show', as: :host_meta, defaults: { format: 'xml' }
  19. get '.well-known/nodeinfo', to: 'well_known/nodeinfo#index', as: :nodeinfo, defaults: { format: 'json' }
  20. get '.well-known/webfinger', to: 'well_known/webfinger#show', as: :webfinger
  21. get '.well-known/change-password', to: redirect('/auth/edit')
  22. get '.well-known/keybase-proof-config', to: 'well_known/keybase_proof_config#show'
  23. get '/nodeinfo/2.0', to: 'well_known/nodeinfo#show', as: :nodeinfo_schema
  24. get 'manifest', to: 'manifests#show', defaults: { format: 'json' }
  25. get 'intent', to: 'intents#show'
  26. get 'custom.css', to: 'custom_css#show', as: :custom_css
  27. resource :instance_actor, path: 'actor', only: [:show] do
  28. resource :inbox, only: [:create], module: :activitypub
  29. resource :outbox, only: [:show], module: :activitypub
  30. end
  31. devise_scope :user do
  32. get '/invite/:invite_code', to: 'auth/registrations#new', as: :public_invite
  33. namespace :auth do
  34. resource :setup, only: [:show, :update], controller: :setup
  35. resource :challenge, only: [:create], controller: :challenges
  36. get 'sessions/security_key_options', to: 'sessions#webauthn_options'
  37. end
  38. end
  39. devise_for :users, path: 'auth', controllers: {
  40. omniauth_callbacks: 'auth/omniauth_callbacks',
  41. sessions: 'auth/sessions',
  42. registrations: 'auth/registrations',
  43. passwords: 'auth/passwords',
  44. confirmations: 'auth/confirmations',
  45. }
  46. get '/users/:username', to: redirect('/@%{username}'), constraints: lambda { |req| req.format.nil? || req.format.html? }
  47. get '/authorize_follow', to: redirect { |_, request| "/authorize_interaction?#{request.params.to_query}" }
  48. resources :accounts, path: 'users', only: [:show], param: :username do
  49. get :remote_follow, to: 'remote_follow#new'
  50. post :remote_follow, to: 'remote_follow#create'
  51. resources :statuses, only: [:show] do
  52. member do
  53. get :activity
  54. get :embed
  55. end
  56. resources :replies, only: [:index], module: :activitypub
  57. end
  58. resources :followers, only: [:index], controller: :follower_accounts
  59. resources :following, only: [:index], controller: :following_accounts
  60. resource :follow, only: [:create], controller: :account_follow
  61. resource :unfollow, only: [:create], controller: :account_unfollow
  62. resource :outbox, only: [:show], module: :activitypub
  63. resource :inbox, only: [:create], module: :activitypub
  64. resource :claim, only: [:create], module: :activitypub
  65. resources :collections, only: [:show], module: :activitypub
  66. resource :followers_synchronization, only: [:show], module: :activitypub
  67. end
  68. resource :inbox, only: [:create], module: :activitypub
  69. get '/@:username', to: 'accounts#show', as: :short_account
  70. get '/@:username/with_replies', to: 'accounts#show', as: :short_account_with_replies
  71. get '/@:username/media', to: 'accounts#show', as: :short_account_media
  72. get '/@:username/tagged/:tag', to: 'accounts#show', as: :short_account_tag
  73. get '/@:account_username/:id', to: 'statuses#show', as: :short_account_status
  74. get '/@:account_username/:id/embed', to: 'statuses#embed', as: :embed_short_account_status
  75. get '/interact/:id', to: 'remote_interaction#new', as: :remote_interaction
  76. post '/interact/:id', to: 'remote_interaction#create'
  77. get '/explore', to: 'directories#index', as: :explore
  78. get '/explore/:id', to: 'directories#show', as: :explore_hashtag
  79. get '/settings', to: redirect('/settings/profile')
  80. namespace :settings do
  81. resource :profile, only: [:show, :update] do
  82. resources :pictures, only: :destroy
  83. end
  84. get :preferences, to: redirect('/settings/preferences/appearance')
  85. namespace :preferences do
  86. resource :appearance, only: [:show, :update], controller: :appearance
  87. resource :notifications, only: [:show, :update]
  88. resource :other, only: [:show, :update], controller: :other
  89. end
  90. resource :import, only: [:show, :create]
  91. resource :export, only: [:show, :create]
  92. namespace :exports, constraints: { format: :csv } do
  93. resources :follows, only: :index, controller: :following_accounts
  94. resources :blocks, only: :index, controller: :blocked_accounts
  95. resources :mutes, only: :index, controller: :muted_accounts
  96. resources :lists, only: :index, controller: :lists
  97. resources :domain_blocks, only: :index, controller: :blocked_domains
  98. end
  99. resources :two_factor_authentication_methods, only: [:index] do
  100. collection do
  101. post :disable
  102. end
  103. end
  104. resource :otp_authentication, only: [:show, :create], controller: 'two_factor_authentication/otp_authentication'
  105. resources :webauthn_credentials, only: [:index, :new, :create, :destroy],
  106. path: 'security_keys',
  107. controller: 'two_factor_authentication/webauthn_credentials' do
  108. collection do
  109. get :options
  110. end
  111. end
  112. namespace :two_factor_authentication do
  113. resources :recovery_codes, only: [:create]
  114. resource :confirmation, only: [:new, :create]
  115. end
  116. resources :identity_proofs, only: [:index, :new, :create, :destroy]
  117. resources :applications, except: [:edit] do
  118. member do
  119. post :regenerate
  120. end
  121. end
  122. resource :delete, only: [:show, :destroy]
  123. resource :migration, only: [:show, :create]
  124. namespace :migration do
  125. resource :redirect, only: [:new, :create, :destroy]
  126. end
  127. resources :aliases, only: [:index, :create, :destroy]
  128. resources :sessions, only: [:destroy]
  129. resources :featured_tags, only: [:index, :create, :destroy]
  130. end
  131. resources :media, only: [:show] do
  132. get :player
  133. end
  134. resources :tags, only: [:show]
  135. resources :emojis, only: [:show]
  136. resources :invites, only: [:index, :create, :destroy]
  137. resources :filters, except: [:show]
  138. resource :relationships, only: [:show, :update]
  139. get '/public', to: 'public_timelines#show', as: :public_timeline
  140. get '/media_proxy/:id/(*any)', to: 'media_proxy#show', as: :media_proxy
  141. resource :authorize_interaction, only: [:show, :create]
  142. resource :share, only: [:show, :create]
  143. namespace :admin do
  144. get '/dashboard', to: 'dashboard#index'
  145. resources :domain_allows, only: [:new, :create, :show, :destroy]
  146. resources :domain_blocks, only: [:new, :create, :show, :destroy, :update, :edit]
  147. resources :email_domain_blocks, only: [:index, :new, :create, :destroy]
  148. resources :action_logs, only: [:index]
  149. resources :warning_presets, except: [:new]
  150. resources :announcements, except: [:show] do
  151. member do
  152. post :publish
  153. post :unpublish
  154. end
  155. end
  156. resource :settings, only: [:edit, :update]
  157. resources :site_uploads, only: [:destroy]
  158. resources :invites, only: [:index, :create, :destroy] do
  159. collection do
  160. post :deactivate_all
  161. end
  162. end
  163. resources :relays, only: [:index, :new, :create, :destroy] do
  164. member do
  165. post :enable
  166. post :disable
  167. end
  168. end
  169. resources :instances, only: [:index, :show], constraints: { id: /[^\/]+/ }
  170. resources :reports, only: [:index, :show] do
  171. member do
  172. post :assign_to_self
  173. post :unassign
  174. post :reopen
  175. post :resolve
  176. end
  177. resources :reported_statuses, only: [:create]
  178. end
  179. resources :report_notes, only: [:create, :destroy]
  180. resources :accounts, only: [:index, :show, :destroy] do
  181. member do
  182. post :enable
  183. post :unsensitive
  184. post :unsilence
  185. post :unsuspend
  186. post :redownload
  187. post :remove_avatar
  188. post :remove_header
  189. post :memorialize
  190. post :approve
  191. post :reject
  192. end
  193. resource :change_email, only: [:show, :update]
  194. resource :reset, only: [:create]
  195. resource :action, only: [:new, :create], controller: 'account_actions'
  196. resources :statuses, only: [:index, :show, :create, :update, :destroy]
  197. resources :relationships, only: [:index]
  198. resource :confirmation, only: [:create] do
  199. collection do
  200. post :resend
  201. end
  202. end
  203. resource :role, only: [] do
  204. member do
  205. post :promote
  206. post :demote
  207. end
  208. end
  209. end
  210. resources :pending_accounts, only: [:index] do
  211. collection do
  212. post :approve_all
  213. post :reject_all
  214. post :batch
  215. end
  216. end
  217. resources :users, only: [] do
  218. resource :two_factor_authentication, only: [:destroy]
  219. end
  220. resources :custom_emojis, only: [:index, :new, :create] do
  221. collection do
  222. post :batch
  223. end
  224. end
  225. resources :ip_blocks, only: [:index, :new, :create] do
  226. collection do
  227. post :batch
  228. end
  229. end
  230. resources :account_moderation_notes, only: [:create, :destroy]
  231. resources :tags, only: [:index, :show, :update] do
  232. collection do
  233. post :approve_all
  234. post :reject_all
  235. post :batch
  236. end
  237. end
  238. end
  239. get '/admin', to: redirect('/admin/dashboard', status: 302)
  240. namespace :api do
  241. # OEmbed
  242. get '/oembed', to: 'oembed#show', as: :oembed
  243. # Identity proofs
  244. get :proofs, to: 'proofs#index'
  245. # JSON / REST API
  246. namespace :v1 do
  247. resources :statuses, only: [:create, :show, :destroy] do
  248. scope module: :statuses do
  249. resources :reblogged_by, controller: :reblogged_by_accounts, only: :index
  250. resources :favourited_by, controller: :favourited_by_accounts, only: :index
  251. resource :reblog, only: :create
  252. post :unreblog, to: 'reblogs#destroy'
  253. resource :favourite, only: :create
  254. post :unfavourite, to: 'favourites#destroy'
  255. resource :bookmark, only: :create
  256. post :unbookmark, to: 'bookmarks#destroy'
  257. resource :mute, only: :create
  258. post :unmute, to: 'mutes#destroy'
  259. resource :pin, only: :create
  260. post :unpin, to: 'pins#destroy'
  261. end
  262. member do
  263. get :context
  264. end
  265. end
  266. namespace :timelines do
  267. resource :home, only: :show, controller: :home
  268. resource :public, only: :show, controller: :public
  269. resources :tag, only: :show
  270. resources :list, only: :show
  271. end
  272. resources :streaming, only: [:index]
  273. resources :custom_emojis, only: [:index]
  274. resources :suggestions, only: [:index, :destroy]
  275. resources :scheduled_statuses, only: [:index, :show, :update, :destroy]
  276. resources :preferences, only: [:index]
  277. resources :announcements, only: [:index] do
  278. scope module: :announcements do
  279. resources :reactions, only: [:update, :destroy]
  280. end
  281. member do
  282. post :dismiss
  283. end
  284. end
  285. # namespace :crypto do
  286. # resources :deliveries, only: :create
  287. # namespace :keys do
  288. # resource :upload, only: [:create]
  289. # resource :query, only: [:create]
  290. # resource :claim, only: [:create]
  291. # resource :count, only: [:show]
  292. # end
  293. # resources :encrypted_messages, only: [:index] do
  294. # collection do
  295. # post :clear
  296. # end
  297. # end
  298. # end
  299. resources :conversations, only: [:index, :destroy] do
  300. member do
  301. post :read
  302. end
  303. end
  304. resources :media, only: [:create, :update, :show]
  305. resources :blocks, only: [:index]
  306. resources :mutes, only: [:index]
  307. resources :favourites, only: [:index]
  308. resources :bookmarks, only: [:index]
  309. resources :reports, only: [:create]
  310. resources :trends, only: [:index]
  311. resources :filters, only: [:index, :create, :show, :update, :destroy]
  312. resources :endorsements, only: [:index]
  313. resources :markers, only: [:index, :create]
  314. namespace :apps do
  315. get :verify_credentials, to: 'credentials#show'
  316. end
  317. resources :apps, only: [:create]
  318. resource :instance, only: [:show] do
  319. resources :peers, only: [:index], controller: 'instances/peers'
  320. resource :activity, only: [:show], controller: 'instances/activity'
  321. end
  322. resource :domain_blocks, only: [:show, :create, :destroy]
  323. resource :directory, only: [:show]
  324. resources :follow_requests, only: [:index] do
  325. member do
  326. post :authorize
  327. post :reject
  328. end
  329. end
  330. resources :notifications, only: [:index, :show] do
  331. collection do
  332. post :clear
  333. end
  334. member do
  335. post :dismiss
  336. end
  337. end
  338. namespace :accounts do
  339. get :verify_credentials, to: 'credentials#show'
  340. patch :update_credentials, to: 'credentials#update'
  341. resource :search, only: :show, controller: :search
  342. resources :relationships, only: :index
  343. end
  344. resources :accounts, only: [:create, :show] do
  345. resources :statuses, only: :index, controller: 'accounts/statuses'
  346. resources :followers, only: :index, controller: 'accounts/follower_accounts'
  347. resources :following, only: :index, controller: 'accounts/following_accounts'
  348. resources :lists, only: :index, controller: 'accounts/lists'
  349. resources :identity_proofs, only: :index, controller: 'accounts/identity_proofs'
  350. resources :featured_tags, only: :index, controller: 'accounts/featured_tags'
  351. member do
  352. post :follow
  353. post :unfollow
  354. post :block
  355. post :unblock
  356. post :mute
  357. post :unmute
  358. end
  359. resource :pin, only: :create, controller: 'accounts/pins'
  360. post :unpin, to: 'accounts/pins#destroy'
  361. resource :note, only: :create, controller: 'accounts/notes'
  362. end
  363. resources :lists, only: [:index, :create, :show, :update, :destroy] do
  364. resource :accounts, only: [:show, :create, :destroy], controller: 'lists/accounts'
  365. end
  366. namespace :featured_tags do
  367. get :suggestions, to: 'suggestions#index'
  368. end
  369. resources :featured_tags, only: [:index, :create, :destroy]
  370. resources :polls, only: [:create, :show] do
  371. resources :votes, only: :create, controller: 'polls/votes'
  372. end
  373. namespace :push do
  374. resource :subscription, only: [:create, :show, :update, :destroy]
  375. end
  376. namespace :admin do
  377. resources :accounts, only: [:index, :show, :destroy] do
  378. member do
  379. post :enable
  380. post :unsensitive
  381. post :unsilence
  382. post :unsuspend
  383. post :approve
  384. post :reject
  385. end
  386. resource :action, only: [:create], controller: 'account_actions'
  387. end
  388. resources :reports, only: [:index, :show] do
  389. member do
  390. post :assign_to_self
  391. post :unassign
  392. post :reopen
  393. post :resolve
  394. end
  395. end
  396. end
  397. end
  398. namespace :v2 do
  399. resources :media, only: [:create]
  400. get '/search', to: 'search#index', as: :search
  401. end
  402. namespace :web do
  403. resource :settings, only: [:update]
  404. resource :embed, only: [:create]
  405. resources :push_subscriptions, only: [:create] do
  406. member do
  407. put :update
  408. end
  409. end
  410. end
  411. end
  412. get '/web/(*any)', to: 'home#index', as: :web
  413. get '/about', to: 'about#show'
  414. get '/about/more', to: 'about#more'
  415. get '/terms', to: 'about#terms'
  416. match '/', via: [:post, :put, :patch, :delete], to: 'application#raise_not_found', format: false
  417. match '*unmatched_route', via: :all, to: 'application#raise_not_found', format: false
  418. end