routes.rb 21 KB

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