routes.rb 21 KB

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