routes.rb 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724
  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. get '/:encoded_at(*path)', to: redirect("/@%{path}"), constraints: { encoded_at: /%40/ }
  93. constraints(username: /[^@\/.]+/) do
  94. get '/@:username', to: 'accounts#show', as: :short_account
  95. get '/@:username/with_replies', to: 'accounts#show', as: :short_account_with_replies
  96. get '/@:username/media', to: 'accounts#show', as: :short_account_media
  97. get '/@:username/tagged/:tag', to: 'accounts#show', as: :short_account_tag
  98. end
  99. constraints(account_username: /[^@\/.]+/) do
  100. get '/@:account_username/following', to: 'following_accounts#index'
  101. get '/@:account_username/followers', to: 'follower_accounts#index'
  102. get '/@:account_username/:id', to: 'statuses#show', as: :short_account_status
  103. get '/@:account_username/:id/embed', to: 'statuses#embed', as: :embed_short_account_status
  104. end
  105. get '/@:username_with_domain/(*any)', to: 'home#index', constraints: { username_with_domain: %r{([^/])+?} }, as: :account_with_domain, format: false
  106. get '/settings', to: redirect('/settings/profile')
  107. namespace :settings do
  108. resource :profile, only: [:show, :update] do
  109. resources :pictures, only: :destroy
  110. end
  111. get :preferences, to: redirect('/settings/preferences/appearance')
  112. namespace :preferences do
  113. resource :appearance, only: [:show, :update], controller: :appearance
  114. resource :notifications, only: [:show, :update]
  115. resource :other, only: [:show, :update], controller: :other
  116. end
  117. resource :import, only: [:show, :create]
  118. resource :export, only: [:show, :create]
  119. namespace :exports, constraints: { format: :csv } do
  120. resources :follows, only: :index, controller: :following_accounts
  121. resources :blocks, only: :index, controller: :blocked_accounts
  122. resources :mutes, only: :index, controller: :muted_accounts
  123. resources :lists, only: :index, controller: :lists
  124. resources :domain_blocks, only: :index, controller: :blocked_domains
  125. resources :bookmarks, only: :index, controller: :bookmarks
  126. end
  127. resources :two_factor_authentication_methods, only: [:index] do
  128. collection do
  129. post :disable
  130. end
  131. end
  132. resource :otp_authentication, only: [:show, :create], controller: 'two_factor_authentication/otp_authentication'
  133. resources :webauthn_credentials, only: [:index, :new, :create, :destroy],
  134. path: 'security_keys',
  135. controller: 'two_factor_authentication/webauthn_credentials' do
  136. collection do
  137. get :options
  138. end
  139. end
  140. namespace :two_factor_authentication do
  141. resources :recovery_codes, only: [:create]
  142. resource :confirmation, only: [:new, :create]
  143. end
  144. resources :applications, except: [:edit] do
  145. member do
  146. post :regenerate
  147. end
  148. end
  149. resource :delete, only: [:show, :destroy]
  150. resource :migration, only: [:show, :create]
  151. namespace :migration do
  152. resource :redirect, only: [:new, :create, :destroy]
  153. end
  154. resources :aliases, only: [:index, :create, :destroy]
  155. resources :sessions, only: [:destroy]
  156. resources :featured_tags, only: [:index, :create, :destroy]
  157. resources :login_activities, only: [:index]
  158. end
  159. namespace :disputes do
  160. resources :strikes, only: [:show, :index] do
  161. resource :appeal, only: [:create]
  162. end
  163. end
  164. resources :media, only: [:show] do
  165. get :player
  166. end
  167. resources :tags, only: [:show]
  168. resources :emojis, only: [:show]
  169. resources :invites, only: [:index, :create, :destroy]
  170. resources :filters, except: [:show] do
  171. resources :statuses, only: [:index], controller: 'filters/statuses' do
  172. collection do
  173. post :batch
  174. end
  175. end
  176. end
  177. resource :relationships, only: [:show, :update]
  178. resource :statuses_cleanup, controller: :statuses_cleanup, only: [:show, :update]
  179. get '/media_proxy/:id/(*any)', to: 'media_proxy#show', as: :media_proxy, format: false
  180. get '/backups/:id/download', to: 'backups#download', as: :download_backup, format: false
  181. resource :authorize_interaction, only: [:show, :create]
  182. resource :share, only: [:show, :create]
  183. namespace :admin do
  184. get '/dashboard', to: 'dashboard#index'
  185. resources :domain_allows, only: [:new, :create, :show, :destroy]
  186. resources :domain_blocks, only: [:new, :create, :show, :destroy, :update, :edit] do
  187. collection do
  188. post :batch
  189. end
  190. end
  191. resources :export_domain_allows, only: [:new] do
  192. collection do
  193. get :export, constraints: { format: :csv }
  194. post :import
  195. end
  196. end
  197. resources :export_domain_blocks, only: [:new] do
  198. collection do
  199. get :export, constraints: { format: :csv }
  200. post :import
  201. end
  202. end
  203. resources :email_domain_blocks, only: [:index, :new, :create] do
  204. collection do
  205. post :batch
  206. end
  207. end
  208. resources :action_logs, only: [:index]
  209. resources :warning_presets, except: [:new]
  210. resources :announcements, except: [:show] do
  211. member do
  212. post :publish
  213. post :unpublish
  214. end
  215. end
  216. get '/settings', to: redirect('/admin/settings/branding')
  217. get '/settings/edit', to: redirect('/admin/settings/branding')
  218. namespace :settings do
  219. resource :branding, only: [:show, :update], controller: 'branding'
  220. resource :registrations, only: [:show, :update], controller: 'registrations'
  221. resource :content_retention, only: [:show, :update], controller: 'content_retention'
  222. resource :about, only: [:show, :update], controller: 'about'
  223. resource :appearance, only: [:show, :update], controller: 'appearance'
  224. resource :discovery, only: [:show, :update], controller: 'discovery'
  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' do
  257. collection do
  258. post :preview
  259. end
  260. end
  261. member do
  262. post :assign_to_self
  263. post :unassign
  264. post :reopen
  265. post :resolve
  266. end
  267. end
  268. resources :report_notes, only: [:create, :destroy]
  269. resources :accounts, only: [:index, :show, :destroy] do
  270. member do
  271. post :enable
  272. post :unsensitive
  273. post :unsilence
  274. post :unsuspend
  275. post :redownload
  276. post :remove_avatar
  277. post :remove_header
  278. post :memorialize
  279. post :approve
  280. post :reject
  281. post :unblock_email
  282. end
  283. collection do
  284. post :batch
  285. end
  286. resource :change_email, only: [:show, :update]
  287. resource :reset, only: [:create]
  288. resource :action, only: [:new, :create], controller: 'account_actions'
  289. resources :statuses, only: [:index, :show] do
  290. collection do
  291. post :batch
  292. end
  293. end
  294. resources :relationships, only: [:index]
  295. resource :confirmation, only: [:create] do
  296. collection do
  297. post :resend
  298. end
  299. end
  300. end
  301. resources :users, only: [] do
  302. resource :two_factor_authentication, only: [:destroy], controller: 'users/two_factor_authentications'
  303. resource :role, only: [:show, :update], controller: 'users/roles'
  304. end
  305. resources :custom_emojis, only: [:index, :new, :create] do
  306. collection do
  307. post :batch
  308. end
  309. end
  310. resources :ip_blocks, only: [:index, :new, :create] do
  311. collection do
  312. post :batch
  313. end
  314. end
  315. resources :roles, except: [:show]
  316. resources :account_moderation_notes, only: [:create, :destroy]
  317. resource :follow_recommendations, only: [:show, :update]
  318. resources :tags, only: [:show, :update]
  319. namespace :trends do
  320. resources :links, only: [:index] do
  321. collection do
  322. post :batch
  323. end
  324. end
  325. resources :tags, only: [:index] do
  326. collection do
  327. post :batch
  328. end
  329. end
  330. resources :statuses, only: [:index] do
  331. collection do
  332. post :batch
  333. end
  334. end
  335. namespace :links do
  336. resources :preview_card_providers, only: [:index], path: :publishers do
  337. collection do
  338. post :batch
  339. end
  340. end
  341. end
  342. end
  343. namespace :disputes do
  344. resources :appeals, only: [:index] do
  345. member do
  346. post :approve
  347. post :reject
  348. end
  349. end
  350. end
  351. end
  352. get '/admin', to: redirect('/admin/dashboard', status: 302)
  353. namespace :api, format: false do
  354. # OEmbed
  355. get '/oembed', to: 'oembed#show', as: :oembed
  356. # JSON / REST API
  357. namespace :v1 do
  358. resources :statuses, only: [:create, :show, :update, :destroy] do
  359. scope module: :statuses do
  360. resources :reblogged_by, controller: :reblogged_by_accounts, only: :index
  361. resources :favourited_by, controller: :favourited_by_accounts, only: :index
  362. resource :reblog, only: :create
  363. post :unreblog, to: 'reblogs#destroy'
  364. resource :favourite, only: :create
  365. post :unfavourite, to: 'favourites#destroy'
  366. resource :bookmark, only: :create
  367. post :unbookmark, to: 'bookmarks#destroy'
  368. resource :mute, only: :create
  369. post :unmute, to: 'mutes#destroy'
  370. resource :pin, only: :create
  371. post :unpin, to: 'pins#destroy'
  372. resource :history, only: :show
  373. resource :source, only: :show
  374. post :translate, to: 'translations#create'
  375. end
  376. member do
  377. get :context
  378. end
  379. end
  380. namespace :timelines do
  381. resource :home, only: :show, controller: :home
  382. resource :public, only: :show, controller: :public
  383. resources :tag, only: :show
  384. resources :list, only: :show
  385. end
  386. get '/streaming', to: 'streaming#index'
  387. get '/streaming/(*any)', to: 'streaming#index'
  388. resources :custom_emojis, only: [:index]
  389. resources :suggestions, only: [:index, :destroy]
  390. resources :scheduled_statuses, only: [:index, :show, :update, :destroy]
  391. resources :preferences, only: [:index]
  392. resources :announcements, only: [:index] do
  393. scope module: :announcements do
  394. resources :reactions, only: [:update, :destroy]
  395. end
  396. member do
  397. post :dismiss
  398. end
  399. end
  400. # namespace :crypto do
  401. # resources :deliveries, only: :create
  402. # namespace :keys do
  403. # resource :upload, only: [:create]
  404. # resource :query, only: [:create]
  405. # resource :claim, only: [:create]
  406. # resource :count, only: [:show]
  407. # end
  408. # resources :encrypted_messages, only: [:index] do
  409. # collection do
  410. # post :clear
  411. # end
  412. # end
  413. # end
  414. resources :conversations, only: [:index, :destroy] do
  415. member do
  416. post :read
  417. end
  418. end
  419. resources :media, only: [:create, :update, :show]
  420. resources :blocks, only: [:index]
  421. resources :mutes, only: [:index]
  422. resources :favourites, only: [:index]
  423. resources :bookmarks, only: [:index]
  424. resources :reports, only: [:create]
  425. resources :trends, only: [:index], controller: 'trends/tags'
  426. resources :filters, only: [:index, :create, :show, :update, :destroy]
  427. resources :endorsements, only: [:index]
  428. resources :markers, only: [:index, :create]
  429. namespace :apps do
  430. get :verify_credentials, to: 'credentials#show'
  431. end
  432. resources :apps, only: [:create]
  433. namespace :trends do
  434. resources :links, only: [:index]
  435. resources :tags, only: [:index]
  436. resources :statuses, only: [:index]
  437. end
  438. namespace :emails do
  439. resources :confirmations, only: [:create]
  440. end
  441. resource :instance, only: [:show] do
  442. resources :peers, only: [:index], controller: 'instances/peers'
  443. resources :rules, only: [:index], controller: 'instances/rules'
  444. resources :domain_blocks, only: [:index], controller: 'instances/domain_blocks'
  445. resource :privacy_policy, only: [:show], controller: 'instances/privacy_policies'
  446. resource :extended_description, only: [:show], controller: 'instances/extended_descriptions'
  447. resource :activity, only: [:show], controller: 'instances/activity'
  448. end
  449. resource :domain_blocks, only: [:show, :create, :destroy]
  450. resource :directory, only: [:show]
  451. resources :follow_requests, only: [:index] do
  452. member do
  453. post :authorize
  454. post :reject
  455. end
  456. end
  457. resources :notifications, only: [:index, :show] do
  458. collection do
  459. post :clear
  460. end
  461. member do
  462. post :dismiss
  463. end
  464. end
  465. namespace :accounts do
  466. get :verify_credentials, to: 'credentials#show'
  467. patch :update_credentials, to: 'credentials#update'
  468. resource :search, only: :show, controller: :search
  469. resource :lookup, only: :show, controller: :lookup
  470. resources :relationships, only: :index
  471. resources :familiar_followers, only: :index
  472. end
  473. resources :accounts, only: [:create, :show] do
  474. resources :statuses, only: :index, controller: 'accounts/statuses'
  475. resources :followers, only: :index, controller: 'accounts/follower_accounts'
  476. resources :following, only: :index, controller: 'accounts/following_accounts'
  477. resources :lists, only: :index, controller: 'accounts/lists'
  478. resources :identity_proofs, only: :index, controller: 'accounts/identity_proofs'
  479. resources :featured_tags, only: :index, controller: 'accounts/featured_tags'
  480. member do
  481. post :follow
  482. post :unfollow
  483. post :remove_from_followers
  484. post :block
  485. post :unblock
  486. post :mute
  487. post :unmute
  488. end
  489. resource :pin, only: :create, controller: 'accounts/pins'
  490. post :unpin, to: 'accounts/pins#destroy'
  491. resource :note, only: :create, controller: 'accounts/notes'
  492. end
  493. resources :tags, only: [:show] do
  494. member do
  495. post :follow
  496. post :unfollow
  497. end
  498. end
  499. resources :followed_tags, only: [:index]
  500. resources :lists, only: [:index, :create, :show, :update, :destroy] do
  501. resource :accounts, only: [:show, :create, :destroy], controller: 'lists/accounts'
  502. end
  503. namespace :featured_tags do
  504. get :suggestions, to: 'suggestions#index'
  505. end
  506. resources :featured_tags, only: [:index, :create, :destroy]
  507. resources :polls, only: [:create, :show] do
  508. resources :votes, only: :create, controller: 'polls/votes'
  509. end
  510. namespace :push do
  511. resource :subscription, only: [:create, :show, :update, :destroy]
  512. end
  513. namespace :admin do
  514. resources :accounts, only: [:index, :show, :destroy] do
  515. member do
  516. post :enable
  517. post :unsensitive
  518. post :unsilence
  519. post :unsuspend
  520. post :approve
  521. post :reject
  522. end
  523. resource :action, only: [:create], controller: 'account_actions'
  524. end
  525. resources :reports, only: [:index, :update, :show] do
  526. member do
  527. post :assign_to_self
  528. post :unassign
  529. post :reopen
  530. post :resolve
  531. end
  532. end
  533. resources :domain_allows, only: [:index, :show, :create, :destroy]
  534. resources :domain_blocks, only: [:index, :show, :update, :create, :destroy]
  535. resources :email_domain_blocks, only: [:index, :show, :create, :destroy]
  536. resources :ip_blocks, only: [:index, :show, :update, :create, :destroy]
  537. namespace :trends do
  538. resources :tags, only: [:index]
  539. resources :links, only: [:index]
  540. resources :statuses, only: [:index]
  541. end
  542. post :measures, to: 'measures#create'
  543. post :dimensions, to: 'dimensions#create'
  544. post :retention, to: 'retention#create'
  545. resources :canonical_email_blocks, only: [:index, :create, :show, :destroy] do
  546. collection do
  547. post :test
  548. end
  549. end
  550. end
  551. end
  552. namespace :v2 do
  553. get '/search', to: 'search#index', as: :search
  554. resources :media, only: [:create]
  555. resources :suggestions, only: [:index]
  556. resource :instance, only: [:show]
  557. resources :filters, only: [:index, :create, :show, :update, :destroy] do
  558. resources :keywords, only: [:index, :create], controller: 'filters/keywords'
  559. resources :statuses, only: [:index, :create], controller: 'filters/statuses'
  560. end
  561. namespace :filters do
  562. resources :keywords, only: [:show, :update, :destroy]
  563. resources :statuses, only: [:show, :destroy]
  564. end
  565. namespace :admin do
  566. resources :accounts, only: [:index]
  567. end
  568. end
  569. namespace :web do
  570. resource :settings, only: [:update]
  571. resource :embed, only: [:create]
  572. resources :push_subscriptions, only: [:create] do
  573. member do
  574. put :update
  575. end
  576. end
  577. end
  578. end
  579. web_app_paths.each do |path|
  580. get path, to: 'home#index'
  581. end
  582. get '/web/(*any)', to: redirect('/%{any}', status: 302), as: :web, defaults: { any: '' }, format: false
  583. get '/about', to: 'about#show'
  584. get '/about/more', to: redirect('/about')
  585. get '/privacy-policy', to: 'privacy#show', as: :privacy_policy
  586. get '/terms', to: redirect('/privacy-policy')
  587. match '/', via: [:post, :put, :patch, :delete], to: 'application#raise_not_found', format: false
  588. match '*unmatched_route', via: :all, to: 'application#raise_not_found', format: false
  589. end