routes.rb 20 KB

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