routes.rb 22 KB

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