routes.rb 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  1. # frozen_string_literal: true
  2. require 'sidekiq_unique_jobs/web'
  3. require 'sidekiq-scheduler/web'
  4. Rails.application.routes.draw do
  5. # Paths of routes on the web app that to not require to be indexed or
  6. # have alternative format representations requiring separate controllers
  7. web_app_paths = %w(
  8. /getting-started
  9. /keyboard-shortcuts
  10. /home
  11. /public
  12. /public/local
  13. /conversations
  14. /lists/(*any)
  15. /notifications
  16. /favourites
  17. /bookmarks
  18. /pinned
  19. /start
  20. /directory
  21. /explore/(*any)
  22. /search
  23. /publish
  24. /follow_requests
  25. /blocks
  26. /domain_blocks
  27. /mutes
  28. /statuses/(*any)
  29. ).freeze
  30. root 'home#index'
  31. mount LetterOpenerWeb::Engine, at: 'letter_opener' if Rails.env.development?
  32. get 'health', to: 'health#show'
  33. authenticate :user, lambda { |u| u.role&.can?(:view_devops) } do
  34. mount Sidekiq::Web, at: 'sidekiq', as: :sidekiq
  35. mount PgHero::Engine, at: 'pghero', as: :pghero
  36. end
  37. use_doorkeeper do
  38. controllers authorizations: 'oauth/authorizations',
  39. authorized_applications: 'oauth/authorized_applications',
  40. tokens: 'oauth/tokens'
  41. end
  42. get '.well-known/host-meta', to: 'well_known/host_meta#show', as: :host_meta, defaults: { format: 'xml' }
  43. get '.well-known/nodeinfo', to: 'well_known/nodeinfo#index', as: :nodeinfo, defaults: { format: 'json' }
  44. get '.well-known/webfinger', to: 'well_known/webfinger#show', as: :webfinger
  45. get '.well-known/change-password', to: redirect('/auth/edit')
  46. get '/nodeinfo/2.0', to: 'well_known/nodeinfo#show', as: :nodeinfo_schema
  47. get 'manifest', to: 'manifests#show', defaults: { format: 'json' }
  48. get 'intent', to: 'intents#show'
  49. get 'custom.css', to: 'custom_css#show', as: :custom_css
  50. resource :instance_actor, path: 'actor', only: [:show] do
  51. resource :inbox, only: [:create], module: :activitypub
  52. resource :outbox, only: [:show], module: :activitypub
  53. end
  54. devise_scope :user do
  55. get '/invite/:invite_code', to: 'auth/registrations#new', as: :public_invite
  56. namespace :auth do
  57. resource :setup, only: [:show, :update], controller: :setup
  58. resource :challenge, only: [:create], controller: :challenges
  59. get 'sessions/security_key_options', to: 'sessions#webauthn_options'
  60. end
  61. end
  62. devise_for :users, path: 'auth', format: false, controllers: {
  63. omniauth_callbacks: 'auth/omniauth_callbacks',
  64. sessions: 'auth/sessions',
  65. registrations: 'auth/registrations',
  66. passwords: 'auth/passwords',
  67. confirmations: 'auth/confirmations',
  68. }
  69. get '/users/:username', to: redirect('/@%{username}'), constraints: lambda { |req| req.format.nil? || req.format.html? }
  70. get '/users/:username/statuses/:id', to: redirect('/@%{username}/%{id}'), constraints: lambda { |req| req.format.nil? || req.format.html? }
  71. get '/authorize_follow', to: redirect { |_, request| "/authorize_interaction?#{request.params.to_query}" }
  72. resources :accounts, path: 'users', only: [:show], param: :username do
  73. resources :statuses, only: [:show] do
  74. member do
  75. get :activity
  76. get :embed
  77. end
  78. resources :replies, only: [:index], module: :activitypub
  79. end
  80. resources :followers, only: [:index], controller: :follower_accounts
  81. resources :following, only: [:index], controller: :following_accounts
  82. resource :follow, only: [:create], controller: :account_follow
  83. resource :unfollow, only: [:create], controller: :account_unfollow
  84. resource :outbox, only: [:show], module: :activitypub
  85. resource :inbox, only: [:create], module: :activitypub
  86. resource :claim, only: [:create], module: :activitypub
  87. resources :collections, only: [:show], module: :activitypub
  88. resource :followers_synchronization, only: [:show], module: :activitypub
  89. end
  90. resource :inbox, only: [:create], module: :activitypub
  91. get '/:encoded_at(*path)', to: redirect("/@%{path}"), constraints: { encoded_at: /%40/ }
  92. constraints(username: /[^@\/.]+/) do
  93. get '/@:username', to: 'accounts#show', as: :short_account
  94. get '/@:username/with_replies', to: 'accounts#show', as: :short_account_with_replies
  95. get '/@:username/media', to: 'accounts#show', as: :short_account_media
  96. get '/@:username/tagged/:tag', to: 'accounts#show', as: :short_account_tag
  97. end
  98. constraints(account_username: /[^@\/.]+/) do
  99. get '/@:account_username/following', to: 'following_accounts#index'
  100. get '/@:account_username/followers', to: 'follower_accounts#index'
  101. get '/@:account_username/:id', to: 'statuses#show', as: :short_account_status
  102. get '/@:account_username/:id/embed', to: 'statuses#embed', as: :embed_short_account_status
  103. end
  104. get '/@:username_with_domain/(*any)', to: 'home#index', constraints: { username_with_domain: /([^\/])+?/ }, format: false
  105. get '/settings', to: redirect('/settings/profile')
  106. namespace :settings do
  107. resource :profile, only: [:show, :update] do
  108. resources :pictures, only: :destroy
  109. end
  110. get :preferences, to: redirect('/settings/preferences/appearance')
  111. namespace :preferences do
  112. resource :appearance, only: [:show, :update], controller: :appearance
  113. resource :notifications, only: [:show, :update]
  114. resource :other, only: [:show, :update], controller: :other
  115. end
  116. resource :import, only: [:show, :create]
  117. resource :export, only: [:show, :create]
  118. namespace :exports, constraints: { format: :csv } do
  119. resources :follows, only: :index, controller: :following_accounts
  120. resources :blocks, only: :index, controller: :blocked_accounts
  121. resources :mutes, only: :index, controller: :muted_accounts
  122. resources :lists, only: :index, controller: :lists
  123. resources :domain_blocks, only: :index, controller: :blocked_domains
  124. resources :bookmarks, only: :index, controller: :bookmarks
  125. end
  126. resources :two_factor_authentication_methods, only: [:index] do
  127. collection do
  128. post :disable
  129. end
  130. end
  131. resource :otp_authentication, only: [:show, :create], controller: 'two_factor_authentication/otp_authentication'
  132. resources :webauthn_credentials, only: [:index, :new, :create, :destroy],
  133. path: 'security_keys',
  134. controller: 'two_factor_authentication/webauthn_credentials' do
  135. collection do
  136. get :options
  137. end
  138. end
  139. namespace :two_factor_authentication do
  140. resources :recovery_codes, only: [:create]
  141. resource :confirmation, only: [:new, :create]
  142. end
  143. resources :applications, except: [:edit] do
  144. member do
  145. post :regenerate
  146. end
  147. end
  148. resource :delete, only: [:show, :destroy]
  149. resource :migration, only: [:show, :create]
  150. namespace :migration do
  151. resource :redirect, only: [:new, :create, :destroy]
  152. end
  153. resources :aliases, only: [:index, :create, :destroy]
  154. resources :sessions, only: [:destroy]
  155. resources :featured_tags, only: [:index, :create, :destroy]
  156. resources :login_activities, only: [:index]
  157. end
  158. namespace :disputes do
  159. resources :strikes, only: [:show, :index] do
  160. resource :appeal, only: [:create]
  161. end
  162. end
  163. resources :media, only: [:show] do
  164. get :player
  165. end
  166. resources :tags, only: [:show]
  167. resources :emojis, only: [:show]
  168. resources :invites, only: [:index, :create, :destroy]
  169. resources :filters, except: [:show] do
  170. resources :statuses, only: [:index], controller: 'filters/statuses' do
  171. collection do
  172. post :batch
  173. end
  174. end
  175. end
  176. resource :relationships, only: [:show, :update]
  177. resource :statuses_cleanup, controller: :statuses_cleanup, only: [:show, :update]
  178. get '/media_proxy/:id/(*any)', to: 'media_proxy#show', as: :media_proxy, format: false
  179. get '/backups/:id/download', to: 'backups#download', as: :download_backup, format: false
  180. resource :authorize_interaction, only: [:show, :create]
  181. resource :share, only: [:show, :create]
  182. namespace :admin do
  183. get '/dashboard', to: 'dashboard#index'
  184. resources :domain_allows, only: [:new, :create, :show, :destroy]
  185. resources :domain_blocks, only: [:new, :create, :destroy, :update, :edit]
  186. resources :email_domain_blocks, only: [:index, :new, :create] do
  187. collection do
  188. post :batch
  189. end
  190. end
  191. resources :action_logs, only: [:index]
  192. resources :warning_presets, except: [:new]
  193. resources :announcements, except: [:show] do
  194. member do
  195. post :publish
  196. post :unpublish
  197. end
  198. end
  199. get '/settings', to: redirect('/admin/settings/branding')
  200. get '/settings/edit', to: redirect('/admin/settings/branding')
  201. namespace :settings do
  202. resource :branding, only: [:show, :update], controller: 'branding'
  203. resource :registrations, only: [:show, :update], controller: 'registrations'
  204. resource :content_retention, only: [:show, :update], controller: 'content_retention'
  205. resource :about, only: [:show, :update], controller: 'about'
  206. resource :appearance, only: [:show, :update], controller: 'appearance'
  207. resource :discovery, only: [:show, :update], controller: 'discovery'
  208. end
  209. resources :site_uploads, only: [:destroy]
  210. resources :invites, only: [:index, :create, :destroy] do
  211. collection do
  212. post :deactivate_all
  213. end
  214. end
  215. resources :relays, only: [:index, :new, :create, :destroy] do
  216. member do
  217. post :enable
  218. post :disable
  219. end
  220. end
  221. resources :instances, only: [:index, :show, :destroy], constraints: { id: /[^\/]+/ }, format: 'html' do
  222. member do
  223. post :clear_delivery_errors
  224. post :restart_delivery
  225. post :stop_delivery
  226. end
  227. end
  228. resources :rules
  229. resources :webhooks do
  230. member do
  231. post :enable
  232. post :disable
  233. end
  234. resource :secret, only: [], controller: 'webhooks/secrets' do
  235. post :rotate
  236. end
  237. end
  238. resources :reports, only: [:index, :show] do
  239. resources :actions, only: [:create], controller: 'reports/actions'
  240. member do
  241. post :assign_to_self
  242. post :unassign
  243. post :reopen
  244. post :resolve
  245. end
  246. end
  247. resources :report_notes, only: [:create, :destroy]
  248. resources :accounts, only: [:index, :show, :destroy] do
  249. member do
  250. post :enable
  251. post :unsensitive
  252. post :unsilence
  253. post :unsuspend
  254. post :redownload
  255. post :remove_avatar
  256. post :remove_header
  257. post :memorialize
  258. post :approve
  259. post :reject
  260. post :unblock_email
  261. end
  262. collection do
  263. post :batch
  264. end
  265. resource :change_email, only: [:show, :update]
  266. resource :reset, only: [:create]
  267. resource :action, only: [:new, :create], controller: 'account_actions'
  268. resources :statuses, only: [:index, :show] do
  269. collection do
  270. post :batch
  271. end
  272. end
  273. resources :relationships, only: [:index]
  274. resource :confirmation, only: [:create] do
  275. collection do
  276. post :resend
  277. end
  278. end
  279. end
  280. resources :users, only: [] do
  281. resource :two_factor_authentication, only: [:destroy], controller: 'users/two_factor_authentications'
  282. resource :role, only: [:show, :update], controller: 'users/roles'
  283. end
  284. resources :custom_emojis, only: [:index, :new, :create] do
  285. collection do
  286. post :batch
  287. end
  288. end
  289. resources :ip_blocks, only: [:index, :new, :create] do
  290. collection do
  291. post :batch
  292. end
  293. end
  294. resources :roles, except: [:show]
  295. resources :account_moderation_notes, only: [:create, :destroy]
  296. resource :follow_recommendations, only: [:show, :update]
  297. resources :tags, only: [:show, :update]
  298. namespace :trends do
  299. resources :links, only: [:index] do
  300. collection do
  301. post :batch
  302. end
  303. end
  304. resources :tags, only: [:index] do
  305. collection do
  306. post :batch
  307. end
  308. end
  309. resources :statuses, only: [:index] do
  310. collection do
  311. post :batch
  312. end
  313. end
  314. namespace :links do
  315. resources :preview_card_providers, only: [:index], path: :publishers do
  316. collection do
  317. post :batch
  318. end
  319. end
  320. end
  321. end
  322. namespace :disputes do
  323. resources :appeals, only: [:index] do
  324. member do
  325. post :approve
  326. post :reject
  327. end
  328. end
  329. end
  330. end
  331. get '/admin', to: redirect('/admin/dashboard', status: 302)
  332. namespace :api, format: false do
  333. # OEmbed
  334. get '/oembed', to: 'oembed#show', as: :oembed
  335. # JSON / REST API
  336. namespace :v1 do
  337. resources :statuses, only: [:create, :show, :update, :destroy] do
  338. scope module: :statuses do
  339. resources :reblogged_by, controller: :reblogged_by_accounts, only: :index
  340. resources :favourited_by, controller: :favourited_by_accounts, only: :index
  341. resource :reblog, only: :create
  342. post :unreblog, to: 'reblogs#destroy'
  343. resource :favourite, only: :create
  344. post :unfavourite, to: 'favourites#destroy'
  345. resource :bookmark, only: :create
  346. post :unbookmark, to: 'bookmarks#destroy'
  347. resource :mute, only: :create
  348. post :unmute, to: 'mutes#destroy'
  349. resource :pin, only: :create
  350. post :unpin, to: 'pins#destroy'
  351. resource :history, only: :show
  352. resource :source, only: :show
  353. post :translate, to: 'translations#create'
  354. end
  355. member do
  356. get :context
  357. end
  358. end
  359. namespace :timelines do
  360. resource :home, only: :show, controller: :home
  361. resource :public, only: :show, controller: :public
  362. resources :tag, only: :show
  363. resources :list, only: :show
  364. end
  365. get '/streaming', to: 'streaming#index'
  366. get '/streaming/(*any)', to: 'streaming#index'
  367. resources :custom_emojis, only: [:index]
  368. resources :suggestions, only: [:index, :destroy]
  369. resources :scheduled_statuses, only: [:index, :show, :update, :destroy]
  370. resources :preferences, only: [:index]
  371. resources :announcements, only: [:index] do
  372. scope module: :announcements do
  373. resources :reactions, only: [:update, :destroy]
  374. end
  375. member do
  376. post :dismiss
  377. end
  378. end
  379. # namespace :crypto do
  380. # resources :deliveries, only: :create
  381. # namespace :keys do
  382. # resource :upload, only: [:create]
  383. # resource :query, only: [:create]
  384. # resource :claim, only: [:create]
  385. # resource :count, only: [:show]
  386. # end
  387. # resources :encrypted_messages, only: [:index] do
  388. # collection do
  389. # post :clear
  390. # end
  391. # end
  392. # end
  393. resources :conversations, only: [:index, :destroy] do
  394. member do
  395. post :read
  396. end
  397. end
  398. resources :media, only: [:create, :update, :show]
  399. resources :blocks, only: [:index]
  400. resources :mutes, only: [:index]
  401. resources :favourites, only: [:index]
  402. resources :bookmarks, only: [:index]
  403. resources :reports, only: [:create]
  404. resources :trends, only: [:index], controller: 'trends/tags'
  405. resources :filters, only: [:index, :create, :show, :update, :destroy]
  406. resources :endorsements, only: [:index]
  407. resources :markers, only: [:index, :create]
  408. namespace :apps do
  409. get :verify_credentials, to: 'credentials#show'
  410. end
  411. resources :apps, only: [:create]
  412. namespace :trends do
  413. resources :links, only: [:index]
  414. resources :tags, only: [:index]
  415. resources :statuses, only: [:index]
  416. end
  417. namespace :emails do
  418. resources :confirmations, only: [:create]
  419. end
  420. resource :instance, only: [:show] do
  421. resources :peers, only: [:index], controller: 'instances/peers'
  422. resources :rules, only: [:index], controller: 'instances/rules'
  423. resources :domain_blocks, only: [:index], controller: 'instances/domain_blocks'
  424. resource :privacy_policy, only: [:show], controller: 'instances/privacy_policies'
  425. resource :extended_description, only: [:show], controller: 'instances/extended_descriptions'
  426. resource :activity, only: [:show], controller: 'instances/activity'
  427. end
  428. resource :domain_blocks, only: [:show, :create, :destroy]
  429. resource :directory, only: [:show]
  430. resources :follow_requests, only: [:index] do
  431. member do
  432. post :authorize
  433. post :reject
  434. end
  435. end
  436. resources :notifications, only: [:index, :show] do
  437. collection do
  438. post :clear
  439. end
  440. member do
  441. post :dismiss
  442. end
  443. end
  444. namespace :accounts do
  445. get :verify_credentials, to: 'credentials#show'
  446. patch :update_credentials, to: 'credentials#update'
  447. resource :search, only: :show, controller: :search
  448. resource :lookup, only: :show, controller: :lookup
  449. resources :relationships, only: :index
  450. resources :familiar_followers, only: :index
  451. end
  452. resources :accounts, only: [:create, :show] do
  453. resources :statuses, only: :index, controller: 'accounts/statuses'
  454. resources :followers, only: :index, controller: 'accounts/follower_accounts'
  455. resources :following, only: :index, controller: 'accounts/following_accounts'
  456. resources :lists, only: :index, controller: 'accounts/lists'
  457. resources :identity_proofs, only: :index, controller: 'accounts/identity_proofs'
  458. resources :featured_tags, only: :index, controller: 'accounts/featured_tags'
  459. member do
  460. post :follow
  461. post :unfollow
  462. post :remove_from_followers
  463. post :block
  464. post :unblock
  465. post :mute
  466. post :unmute
  467. end
  468. resource :pin, only: :create, controller: 'accounts/pins'
  469. post :unpin, to: 'accounts/pins#destroy'
  470. resource :note, only: :create, controller: 'accounts/notes'
  471. end
  472. resources :tags, only: [:show] do
  473. member do
  474. post :follow
  475. post :unfollow
  476. end
  477. end
  478. resources :followed_tags, only: [:index]
  479. resources :lists, only: [:index, :create, :show, :update, :destroy] do
  480. resource :accounts, only: [:show, :create, :destroy], controller: 'lists/accounts'
  481. end
  482. namespace :featured_tags do
  483. get :suggestions, to: 'suggestions#index'
  484. end
  485. resources :featured_tags, only: [:index, :create, :destroy]
  486. resources :polls, only: [:create, :show] do
  487. resources :votes, only: :create, controller: 'polls/votes'
  488. end
  489. namespace :push do
  490. resource :subscription, only: [:create, :show, :update, :destroy]
  491. end
  492. namespace :admin do
  493. resources :accounts, only: [:index, :show, :destroy] do
  494. member do
  495. post :enable
  496. post :unsensitive
  497. post :unsilence
  498. post :unsuspend
  499. post :approve
  500. post :reject
  501. end
  502. resource :action, only: [:create], controller: 'account_actions'
  503. end
  504. resources :reports, only: [:index, :update, :show] do
  505. member do
  506. post :assign_to_self
  507. post :unassign
  508. post :reopen
  509. post :resolve
  510. end
  511. end
  512. resources :domain_allows, only: [:index, :show, :create, :destroy]
  513. resources :domain_blocks, only: [:index, :show, :update, :create, :destroy]
  514. resources :email_domain_blocks, only: [:index, :show, :create, :destroy]
  515. resources :ip_blocks, only: [:index, :show, :update, :create, :destroy]
  516. namespace :trends do
  517. resources :tags, only: [:index]
  518. resources :links, only: [:index]
  519. resources :statuses, only: [:index]
  520. end
  521. post :measures, to: 'measures#create'
  522. post :dimensions, to: 'dimensions#create'
  523. post :retention, to: 'retention#create'
  524. resources :canonical_email_blocks, only: [:index, :create, :show, :destroy] do
  525. collection do
  526. post :test
  527. end
  528. end
  529. end
  530. end
  531. namespace :v2 do
  532. get '/search', to: 'search#index', as: :search
  533. resources :media, only: [:create]
  534. resources :suggestions, only: [:index]
  535. resource :instance, only: [:show]
  536. resources :filters, only: [:index, :create, :show, :update, :destroy] do
  537. resources :keywords, only: [:index, :create], controller: 'filters/keywords'
  538. resources :statuses, only: [:index, :create], controller: 'filters/statuses'
  539. end
  540. namespace :filters do
  541. resources :keywords, only: [:show, :update, :destroy]
  542. resources :statuses, only: [:show, :destroy]
  543. end
  544. namespace :admin do
  545. resources :accounts, only: [:index]
  546. end
  547. end
  548. namespace :web do
  549. resource :settings, only: [:update]
  550. resource :embed, only: [:create]
  551. resources :push_subscriptions, only: [:create] do
  552. member do
  553. put :update
  554. end
  555. end
  556. end
  557. end
  558. web_app_paths.each do |path|
  559. get path, to: 'home#index'
  560. end
  561. get '/web/(*any)', to: redirect('/%{any}', status: 302), as: :web, defaults: { any: '' }, format: false
  562. get '/about', to: 'about#show'
  563. get '/about/more', to: redirect('/about')
  564. get '/privacy-policy', to: 'privacy#show', as: :privacy_policy
  565. get '/terms', to: redirect('/privacy-policy')
  566. match '/', via: [:post, :put, :patch, :delete], to: 'application#raise_not_found', format: false
  567. match '*unmatched_route', via: :all, to: 'application#raise_not_found', format: false
  568. end