routes.rb 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  1. # frozen_string_literal: true
  2. require 'sidekiq_unique_jobs/web' if ENV['ENABLE_SIDEKIQ_UNIQUE_JOBS_UI'] == true
  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, :show, :destroy, :update, :edit] do
  186. collection do
  187. post :batch
  188. end
  189. end
  190. resources :export_domain_allows, only: [:new] do
  191. collection do
  192. get :export, constraints: { format: :csv }
  193. post :import
  194. end
  195. end
  196. resources :export_domain_blocks, only: [:new] do
  197. collection do
  198. get :export, constraints: { format: :csv }
  199. post :import
  200. end
  201. end
  202. resources :email_domain_blocks, only: [:index, :new, :create] do
  203. collection do
  204. post :batch
  205. end
  206. end
  207. resources :action_logs, only: [:index]
  208. resources :warning_presets, except: [:new]
  209. resources :announcements, except: [:show] do
  210. member do
  211. post :publish
  212. post :unpublish
  213. end
  214. end
  215. get '/settings', to: redirect('/admin/settings/branding')
  216. get '/settings/edit', to: redirect('/admin/settings/branding')
  217. namespace :settings do
  218. resource :branding, only: [:show, :update], controller: 'branding'
  219. resource :registrations, only: [:show, :update], controller: 'registrations'
  220. resource :content_retention, only: [:show, :update], controller: 'content_retention'
  221. resource :about, only: [:show, :update], controller: 'about'
  222. resource :appearance, only: [:show, :update], controller: 'appearance'
  223. resource :discovery, only: [:show, :update], controller: 'discovery'
  224. resource :hometown, only: [:show, :update], controller: 'hometown'
  225. end
  226. resources :site_uploads, only: [:destroy]
  227. resources :invites, only: [:index, :create, :destroy] do
  228. collection do
  229. post :deactivate_all
  230. end
  231. end
  232. resources :relays, only: [:index, :new, :create, :destroy] do
  233. member do
  234. post :enable
  235. post :disable
  236. end
  237. end
  238. resources :instances, only: [:index, :show, :destroy], constraints: { id: /[^\/]+/ }, format: 'html' do
  239. member do
  240. post :clear_delivery_errors
  241. post :restart_delivery
  242. post :stop_delivery
  243. end
  244. end
  245. resources :rules
  246. resources :webhooks do
  247. member do
  248. post :enable
  249. post :disable
  250. end
  251. resource :secret, only: [], controller: 'webhooks/secrets' do
  252. post :rotate
  253. end
  254. end
  255. resources :reports, only: [:index, :show] do
  256. resources :actions, only: [:create], controller: 'reports/actions'
  257. member do
  258. post :assign_to_self
  259. post :unassign
  260. post :reopen
  261. post :resolve
  262. end
  263. end
  264. resources :report_notes, only: [:create, :destroy]
  265. resources :accounts, only: [:index, :show, :destroy] do
  266. member do
  267. post :enable
  268. post :unsensitive
  269. post :unsilence
  270. post :unsuspend
  271. post :redownload
  272. post :remove_avatar
  273. post :remove_header
  274. post :memorialize
  275. post :approve
  276. post :reject
  277. post :unblock_email
  278. end
  279. collection do
  280. post :batch
  281. end
  282. resource :change_email, only: [:show, :update]
  283. resource :reset, only: [:create]
  284. resource :action, only: [:new, :create], controller: 'account_actions'
  285. resources :statuses, only: [:index, :show] do
  286. collection do
  287. post :batch
  288. end
  289. end
  290. resources :relationships, only: [:index]
  291. resource :confirmation, only: [:create] do
  292. collection do
  293. post :resend
  294. end
  295. end
  296. end
  297. resources :users, only: [] do
  298. resource :two_factor_authentication, only: [:destroy], controller: 'users/two_factor_authentications'
  299. resource :role, only: [:show, :update], controller: 'users/roles'
  300. end
  301. resources :custom_emojis, only: [:index, :new, :create] do
  302. collection do
  303. post :batch
  304. end
  305. end
  306. resources :ip_blocks, only: [:index, :new, :create] do
  307. collection do
  308. post :batch
  309. end
  310. end
  311. resources :roles, except: [:show]
  312. resources :account_moderation_notes, only: [:create, :destroy]
  313. resource :follow_recommendations, only: [:show, :update]
  314. resources :tags, only: [:show, :update]
  315. namespace :trends do
  316. resources :links, only: [:index] do
  317. collection do
  318. post :batch
  319. end
  320. end
  321. resources :tags, only: [:index] do
  322. collection do
  323. post :batch
  324. end
  325. end
  326. resources :statuses, only: [:index] do
  327. collection do
  328. post :batch
  329. end
  330. end
  331. namespace :links do
  332. resources :preview_card_providers, only: [:index], path: :publishers do
  333. collection do
  334. post :batch
  335. end
  336. end
  337. end
  338. end
  339. namespace :disputes do
  340. resources :appeals, only: [:index] do
  341. member do
  342. post :approve
  343. post :reject
  344. end
  345. end
  346. end
  347. end
  348. get '/admin', to: redirect('/admin/dashboard', status: 302)
  349. namespace :api, format: false do
  350. # OEmbed
  351. get '/oembed', to: 'oembed#show', as: :oembed
  352. # JSON / REST API
  353. namespace :v1 do
  354. resources :statuses, only: [:create, :show, :update, :destroy] do
  355. scope module: :statuses do
  356. resources :reblogged_by, controller: :reblogged_by_accounts, only: :index
  357. resources :favourited_by, controller: :favourited_by_accounts, only: :index
  358. resource :reblog, only: :create
  359. post :unreblog, to: 'reblogs#destroy'
  360. resource :favourite, only: :create
  361. post :unfavourite, to: 'favourites#destroy'
  362. resource :bookmark, only: :create
  363. post :unbookmark, to: 'bookmarks#destroy'
  364. resource :mute, only: :create
  365. post :unmute, to: 'mutes#destroy'
  366. resource :pin, only: :create
  367. post :unpin, to: 'pins#destroy'
  368. resource :history, only: :show
  369. resource :source, only: :show
  370. post :translate, to: 'translations#create'
  371. end
  372. member do
  373. get :context
  374. end
  375. end
  376. namespace :timelines do
  377. resource :home, only: :show, controller: :home
  378. resource :public, only: :show, controller: :public
  379. resources :tag, only: :show
  380. resources :list, only: :show
  381. end
  382. get '/streaming', to: 'streaming#index'
  383. get '/streaming/(*any)', to: 'streaming#index'
  384. resources :custom_emojis, only: [:index]
  385. resources :suggestions, only: [:index, :destroy]
  386. resources :scheduled_statuses, only: [:index, :show, :update, :destroy]
  387. resources :preferences, only: [:index]
  388. resources :announcements, only: [:index] do
  389. scope module: :announcements do
  390. resources :reactions, only: [:update, :destroy]
  391. end
  392. member do
  393. post :dismiss
  394. end
  395. end
  396. # namespace :crypto do
  397. # resources :deliveries, only: :create
  398. # namespace :keys do
  399. # resource :upload, only: [:create]
  400. # resource :query, only: [:create]
  401. # resource :claim, only: [:create]
  402. # resource :count, only: [:show]
  403. # end
  404. # resources :encrypted_messages, only: [:index] do
  405. # collection do
  406. # post :clear
  407. # end
  408. # end
  409. # end
  410. resources :conversations, only: [:index, :destroy] do
  411. member do
  412. post :read
  413. end
  414. end
  415. resources :media, only: [:create, :update, :show]
  416. resources :blocks, only: [:index]
  417. resources :mutes, only: [:index]
  418. resources :favourites, only: [:index]
  419. resources :bookmarks, only: [:index]
  420. resources :reports, only: [:create]
  421. resources :trends, only: [:index], controller: 'trends/tags'
  422. resources :filters, only: [:index, :create, :show, :update, :destroy]
  423. resources :endorsements, only: [:index]
  424. resources :markers, only: [:index, :create]
  425. namespace :apps do
  426. get :verify_credentials, to: 'credentials#show'
  427. end
  428. resources :apps, only: [:create]
  429. namespace :trends do
  430. resources :links, only: [:index]
  431. resources :tags, only: [:index]
  432. resources :statuses, only: [:index]
  433. end
  434. namespace :emails do
  435. resources :confirmations, only: [:create]
  436. end
  437. resource :instance, only: [:show] do
  438. resources :peers, only: [:index], controller: 'instances/peers'
  439. resources :rules, only: [:index], controller: 'instances/rules'
  440. resources :domain_blocks, only: [:index], controller: 'instances/domain_blocks'
  441. resource :privacy_policy, only: [:show], controller: 'instances/privacy_policies'
  442. resource :extended_description, only: [:show], controller: 'instances/extended_descriptions'
  443. resource :activity, only: [:show], controller: 'instances/activity'
  444. end
  445. resource :domain_blocks, only: [:show, :create, :destroy]
  446. resource :directory, only: [:show]
  447. resources :follow_requests, only: [:index] do
  448. member do
  449. post :authorize
  450. post :reject
  451. end
  452. end
  453. resources :notifications, only: [:index, :show] do
  454. collection do
  455. post :clear
  456. end
  457. member do
  458. post :dismiss
  459. end
  460. end
  461. namespace :accounts do
  462. get :verify_credentials, to: 'credentials#show'
  463. patch :update_credentials, to: 'credentials#update'
  464. resource :search, only: :show, controller: :search
  465. resource :lookup, only: :show, controller: :lookup
  466. resources :relationships, only: :index
  467. resources :familiar_followers, only: :index
  468. end
  469. resources :accounts, only: [:create, :show] do
  470. resources :statuses, only: :index, controller: 'accounts/statuses'
  471. resources :followers, only: :index, controller: 'accounts/follower_accounts'
  472. resources :following, only: :index, controller: 'accounts/following_accounts'
  473. resources :lists, only: :index, controller: 'accounts/lists'
  474. resources :identity_proofs, only: :index, controller: 'accounts/identity_proofs'
  475. resources :featured_tags, only: :index, controller: 'accounts/featured_tags'
  476. member do
  477. post :follow
  478. post :unfollow
  479. post :remove_from_followers
  480. post :block
  481. post :unblock
  482. post :mute
  483. post :unmute
  484. end
  485. resource :pin, only: :create, controller: 'accounts/pins'
  486. post :unpin, to: 'accounts/pins#destroy'
  487. resource :note, only: :create, controller: 'accounts/notes'
  488. end
  489. resources :tags, only: [:show] do
  490. member do
  491. post :follow
  492. post :unfollow
  493. end
  494. end
  495. resources :followed_tags, only: [:index]
  496. resources :lists, only: [:index, :create, :show, :update, :destroy] do
  497. resource :accounts, only: [:show, :create, :destroy], controller: 'lists/accounts'
  498. end
  499. namespace :featured_tags do
  500. get :suggestions, to: 'suggestions#index'
  501. end
  502. resources :featured_tags, only: [:index, :create, :destroy]
  503. resources :polls, only: [:create, :show] do
  504. resources :votes, only: :create, controller: 'polls/votes'
  505. end
  506. namespace :push do
  507. resource :subscription, only: [:create, :show, :update, :destroy]
  508. end
  509. namespace :admin do
  510. resources :accounts, only: [:index, :show, :destroy] do
  511. member do
  512. post :enable
  513. post :unsensitive
  514. post :unsilence
  515. post :unsuspend
  516. post :approve
  517. post :reject
  518. end
  519. resource :action, only: [:create], controller: 'account_actions'
  520. end
  521. resources :reports, only: [:index, :update, :show] do
  522. member do
  523. post :assign_to_self
  524. post :unassign
  525. post :reopen
  526. post :resolve
  527. end
  528. end
  529. resources :domain_allows, only: [:index, :show, :create, :destroy]
  530. resources :domain_blocks, only: [:index, :show, :update, :create, :destroy]
  531. resources :email_domain_blocks, only: [:index, :show, :create, :destroy]
  532. resources :ip_blocks, only: [:index, :show, :update, :create, :destroy]
  533. namespace :trends do
  534. resources :tags, only: [:index]
  535. resources :links, only: [:index]
  536. resources :statuses, only: [:index]
  537. end
  538. post :measures, to: 'measures#create'
  539. post :dimensions, to: 'dimensions#create'
  540. post :retention, to: 'retention#create'
  541. resources :canonical_email_blocks, only: [:index, :create, :show, :destroy] do
  542. collection do
  543. post :test
  544. end
  545. end
  546. end
  547. end
  548. namespace :v2 do
  549. get '/search', to: 'search#index', as: :search
  550. resources :media, only: [:create]
  551. resources :suggestions, only: [:index]
  552. resource :instance, only: [:show]
  553. resources :filters, only: [:index, :create, :show, :update, :destroy] do
  554. resources :keywords, only: [:index, :create], controller: 'filters/keywords'
  555. resources :statuses, only: [:index, :create], controller: 'filters/statuses'
  556. end
  557. namespace :filters do
  558. resources :keywords, only: [:show, :update, :destroy]
  559. resources :statuses, only: [:show, :destroy]
  560. end
  561. namespace :admin do
  562. resources :accounts, only: [:index]
  563. end
  564. end
  565. namespace :web do
  566. resource :settings, only: [:update]
  567. resource :embed, only: [:create]
  568. resources :push_subscriptions, only: [:create] do
  569. member do
  570. put :update
  571. end
  572. end
  573. end
  574. end
  575. web_app_paths.each do |path|
  576. get path, to: 'home#index'
  577. end
  578. get '/web/(*any)', to: redirect('/%{any}', status: 302), as: :web, defaults: { any: '' }, format: false
  579. get '/about', to: 'about#show'
  580. get '/about/more', to: redirect('/about')
  581. get '/privacy-policy', to: 'privacy#show', as: :privacy_policy
  582. get '/terms', to: redirect('/privacy-policy')
  583. match '/', via: [:post, :put, :patch, :delete], to: 'application#raise_not_found', format: false
  584. match '*unmatched_route', via: :all, to: 'application#raise_not_found', format: false
  585. end