routes.rb 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  1. # frozen_string_literal: true
  2. require 'sidekiq_unique_jobs/web'
  3. require 'sidekiq-scheduler/web'
  4. Rails.application.routes.draw do
  5. root 'home#index'
  6. mount LetterOpenerWeb::Engine, at: 'letter_opener' if Rails.env.development?
  7. get 'health', to: 'health#show'
  8. authenticate :user, lambda { |u| u.admin? } do
  9. mount Sidekiq::Web, at: 'sidekiq', as: :sidekiq
  10. mount PgHero::Engine, at: 'pghero', as: :pghero
  11. end
  12. use_doorkeeper do
  13. controllers authorizations: 'oauth/authorizations',
  14. authorized_applications: 'oauth/authorized_applications',
  15. tokens: 'oauth/tokens'
  16. end
  17. get '.well-known/host-meta', to: 'well_known/host_meta#show', as: :host_meta, defaults: { format: 'xml' }
  18. get '.well-known/nodeinfo', to: 'well_known/nodeinfo#index', as: :nodeinfo, defaults: { format: 'json' }
  19. get '.well-known/webfinger', to: 'well_known/webfinger#show', as: :webfinger
  20. get '.well-known/change-password', to: redirect('/auth/edit')
  21. get '/nodeinfo/2.0', to: 'well_known/nodeinfo#show', as: :nodeinfo_schema
  22. get 'manifest', to: 'manifests#show', defaults: { format: 'json' }
  23. get 'intent', to: 'intents#show'
  24. get 'custom.css', to: 'custom_css#show', as: :custom_css
  25. resource :instance_actor, path: 'actor', only: [:show] do
  26. resource :inbox, only: [:create], module: :activitypub
  27. resource :outbox, only: [:show], module: :activitypub
  28. end
  29. devise_scope :user do
  30. get '/invite/:invite_code', to: 'auth/registrations#new', as: :public_invite
  31. namespace :auth do
  32. resource :setup, only: [:show, :update], controller: :setup
  33. resource :challenge, only: [:create], controller: :challenges
  34. get 'sessions/security_key_options', to: 'sessions#webauthn_options'
  35. end
  36. end
  37. devise_for :users, path: 'auth', controllers: {
  38. omniauth_callbacks: 'auth/omniauth_callbacks',
  39. sessions: 'auth/sessions',
  40. registrations: 'auth/registrations',
  41. passwords: 'auth/passwords',
  42. confirmations: 'auth/confirmations',
  43. }
  44. get '/users/:username', to: redirect('/@%{username}'), constraints: lambda { |req| req.format.nil? || req.format.html? }
  45. get '/authorize_follow', to: redirect { |_, request| "/authorize_interaction?#{request.params.to_query}" }
  46. resources :accounts, path: 'users', only: [:show], param: :username do
  47. get :remote_follow, to: 'remote_follow#new'
  48. post :remote_follow, to: 'remote_follow#create'
  49. resources :statuses, only: [:show] do
  50. member do
  51. get :activity
  52. get :embed
  53. end
  54. resources :replies, only: [:index], module: :activitypub
  55. end
  56. resources :followers, only: [:index], controller: :follower_accounts
  57. resources :following, only: [:index], controller: :following_accounts
  58. resource :follow, only: [:create], controller: :account_follow
  59. resource :unfollow, only: [:create], controller: :account_unfollow
  60. resource :outbox, only: [:show], module: :activitypub
  61. resource :inbox, only: [:create], module: :activitypub
  62. resource :claim, only: [:create], module: :activitypub
  63. resources :collections, only: [:show], module: :activitypub
  64. resource :followers_synchronization, only: [:show], module: :activitypub
  65. end
  66. resource :inbox, only: [:create], module: :activitypub
  67. get '/@:username', to: 'accounts#show', as: :short_account
  68. get '/@:username/with_replies', to: 'accounts#show', as: :short_account_with_replies
  69. get '/@:username/media', to: 'accounts#show', as: :short_account_media
  70. get '/@:username/tagged/:tag', to: 'accounts#show', as: :short_account_tag
  71. get '/@:account_username/:id', to: 'statuses#show', as: :short_account_status
  72. get '/@:account_username/:id/embed', to: 'statuses#embed', as: :embed_short_account_status
  73. get '/interact/:id', to: 'remote_interaction#new', as: :remote_interaction
  74. post '/interact/:id', to: 'remote_interaction#create'
  75. get '/explore', to: 'directories#index', as: :explore
  76. get '/settings', to: redirect('/settings/profile')
  77. namespace :settings do
  78. resource :profile, only: [:show, :update] do
  79. resources :pictures, only: :destroy
  80. end
  81. get :preferences, to: redirect('/settings/preferences/appearance')
  82. namespace :preferences do
  83. resource :appearance, only: [:show, :update], controller: :appearance
  84. resource :notifications, only: [:show, :update]
  85. resource :other, only: [:show, :update], controller: :other
  86. end
  87. resource :import, only: [:show, :create]
  88. resource :export, only: [:show, :create]
  89. namespace :exports, constraints: { format: :csv } do
  90. resources :follows, only: :index, controller: :following_accounts
  91. resources :blocks, only: :index, controller: :blocked_accounts
  92. resources :mutes, only: :index, controller: :muted_accounts
  93. resources :lists, only: :index, controller: :lists
  94. resources :domain_blocks, only: :index, controller: :blocked_domains
  95. resources :bookmarks, only: :index, controller: :bookmarks
  96. end
  97. resources :two_factor_authentication_methods, only: [:index] do
  98. collection do
  99. post :disable
  100. end
  101. end
  102. resource :otp_authentication, only: [:show, :create], controller: 'two_factor_authentication/otp_authentication'
  103. resources :webauthn_credentials, only: [:index, :new, :create, :destroy],
  104. path: 'security_keys',
  105. controller: 'two_factor_authentication/webauthn_credentials' do
  106. collection do
  107. get :options
  108. end
  109. end
  110. namespace :two_factor_authentication do
  111. resources :recovery_codes, only: [:create]
  112. resource :confirmation, only: [:new, :create]
  113. end
  114. resources :applications, except: [:edit] do
  115. member do
  116. post :regenerate
  117. end
  118. end
  119. resource :delete, only: [:show, :destroy]
  120. resource :migration, only: [:show, :create]
  121. namespace :migration do
  122. resource :redirect, only: [:new, :create, :destroy]
  123. end
  124. resources :aliases, only: [:index, :create, :destroy]
  125. resources :sessions, only: [:destroy]
  126. resources :featured_tags, only: [:index, :create, :destroy]
  127. resources :login_activities, only: [:index]
  128. end
  129. namespace :disputes do
  130. resources :strikes, only: [:show, :index] do
  131. resource :appeal, only: [:create]
  132. end
  133. end
  134. resources :media, only: [:show] do
  135. get :player
  136. end
  137. resources :tags, only: [:show]
  138. resources :emojis, only: [:show]
  139. resources :invites, only: [:index, :create, :destroy]
  140. resources :filters, except: [:show]
  141. resource :relationships, only: [:show, :update]
  142. resource :statuses_cleanup, controller: :statuses_cleanup, only: [:show, :update]
  143. get '/public', to: 'public_timelines#show', as: :public_timeline
  144. get '/media_proxy/:id/(*any)', to: 'media_proxy#show', as: :media_proxy
  145. resource :authorize_interaction, only: [:show, :create]
  146. resource :share, only: [:show, :create]
  147. namespace :admin do
  148. get '/dashboard', to: 'dashboard#index'
  149. resources :domain_allows, only: [:new, :create, :show, :destroy]
  150. resources :domain_blocks, only: [:new, :create, :destroy, :update, :edit]
  151. resources :email_domain_blocks, only: [:index, :new, :create] do
  152. collection do
  153. post :batch
  154. end
  155. end
  156. resources :action_logs, only: [:index]
  157. resources :warning_presets, except: [:new]
  158. resources :announcements, except: [:show] do
  159. member do
  160. post :publish
  161. post :unpublish
  162. end
  163. end
  164. resource :settings, only: [:edit, :update]
  165. resources :site_uploads, only: [:destroy]
  166. resources :invites, only: [:index, :create, :destroy] do
  167. collection do
  168. post :deactivate_all
  169. end
  170. end
  171. resources :relays, only: [:index, :new, :create, :destroy] do
  172. member do
  173. post :enable
  174. post :disable
  175. end
  176. end
  177. resources :instances, only: [:index, :show, :destroy], constraints: { id: /[^\/]+/ } do
  178. member do
  179. post :clear_delivery_errors
  180. post :restart_delivery
  181. post :stop_delivery
  182. end
  183. end
  184. resources :rules
  185. resources :webhooks do
  186. member do
  187. post :enable
  188. post :disable
  189. end
  190. resource :secret, only: [], controller: 'webhooks/secrets' do
  191. post :rotate
  192. end
  193. end
  194. resources :reports, only: [:index, :show] do
  195. resources :actions, only: [:create], controller: 'reports/actions'
  196. member do
  197. post :assign_to_self
  198. post :unassign
  199. post :reopen
  200. post :resolve
  201. end
  202. end
  203. resources :report_notes, only: [:create, :destroy]
  204. resources :accounts, only: [:index, :show, :destroy] do
  205. member do
  206. post :enable
  207. post :unsensitive
  208. post :unsilence
  209. post :unsuspend
  210. post :redownload
  211. post :remove_avatar
  212. post :remove_header
  213. post :memorialize
  214. post :approve
  215. post :reject
  216. post :unblock_email
  217. end
  218. collection do
  219. post :batch
  220. end
  221. resource :change_email, only: [:show, :update]
  222. resource :reset, only: [:create]
  223. resource :action, only: [:new, :create], controller: 'account_actions'
  224. resources :statuses, only: [:index] do
  225. collection do
  226. post :batch
  227. end
  228. end
  229. resources :relationships, only: [:index]
  230. resource :confirmation, only: [:create] do
  231. collection do
  232. post :resend
  233. end
  234. end
  235. resource :role, only: [] do
  236. member do
  237. post :promote
  238. post :demote
  239. end
  240. end
  241. end
  242. resources :users, only: [] do
  243. resource :two_factor_authentication, only: [:destroy]
  244. end
  245. resources :custom_emojis, only: [:index, :new, :create] do
  246. collection do
  247. post :batch
  248. end
  249. end
  250. resources :ip_blocks, only: [:index, :new, :create] do
  251. collection do
  252. post :batch
  253. end
  254. end
  255. resources :account_moderation_notes, only: [:create, :destroy]
  256. resource :follow_recommendations, only: [:show, :update]
  257. resources :tags, only: [:show, :update]
  258. namespace :trends do
  259. resources :links, only: [:index] do
  260. collection do
  261. post :batch
  262. end
  263. end
  264. resources :tags, only: [:index] do
  265. collection do
  266. post :batch
  267. end
  268. end
  269. resources :statuses, only: [:index] do
  270. collection do
  271. post :batch
  272. end
  273. end
  274. namespace :links do
  275. resources :preview_card_providers, only: [:index], path: :publishers do
  276. collection do
  277. post :batch
  278. end
  279. end
  280. end
  281. end
  282. namespace :disputes do
  283. resources :appeals, only: [:index] do
  284. member do
  285. post :approve
  286. post :reject
  287. end
  288. end
  289. end
  290. end
  291. get '/admin', to: redirect('/admin/dashboard', status: 302)
  292. namespace :api do
  293. # OEmbed
  294. get '/oembed', to: 'oembed#show', as: :oembed
  295. # JSON / REST API
  296. namespace :v1 do
  297. resources :statuses, only: [:create, :show, :update, :destroy] do
  298. scope module: :statuses do
  299. resources :reblogged_by, controller: :reblogged_by_accounts, only: :index
  300. resources :favourited_by, controller: :favourited_by_accounts, only: :index
  301. resource :reblog, only: :create
  302. post :unreblog, to: 'reblogs#destroy'
  303. resource :favourite, only: :create
  304. post :unfavourite, to: 'favourites#destroy'
  305. resource :bookmark, only: :create
  306. post :unbookmark, to: 'bookmarks#destroy'
  307. resource :mute, only: :create
  308. post :unmute, to: 'mutes#destroy'
  309. resource :pin, only: :create
  310. post :unpin, to: 'pins#destroy'
  311. resource :history, only: :show
  312. resource :source, only: :show
  313. end
  314. member do
  315. get :context
  316. end
  317. end
  318. namespace :timelines do
  319. resource :home, only: :show, controller: :home
  320. resource :public, only: :show, controller: :public
  321. resources :tag, only: :show
  322. resources :list, only: :show
  323. end
  324. resources :streaming, only: [:index]
  325. resources :custom_emojis, only: [:index]
  326. resources :suggestions, only: [:index, :destroy]
  327. resources :scheduled_statuses, only: [:index, :show, :update, :destroy]
  328. resources :preferences, only: [:index]
  329. resources :announcements, only: [:index] do
  330. scope module: :announcements do
  331. resources :reactions, only: [:update, :destroy]
  332. end
  333. member do
  334. post :dismiss
  335. end
  336. end
  337. # namespace :crypto do
  338. # resources :deliveries, only: :create
  339. # namespace :keys do
  340. # resource :upload, only: [:create]
  341. # resource :query, only: [:create]
  342. # resource :claim, only: [:create]
  343. # resource :count, only: [:show]
  344. # end
  345. # resources :encrypted_messages, only: [:index] do
  346. # collection do
  347. # post :clear
  348. # end
  349. # end
  350. # end
  351. resources :conversations, only: [:index, :destroy] do
  352. member do
  353. post :read
  354. end
  355. end
  356. resources :media, only: [:create, :update, :show]
  357. resources :blocks, only: [:index]
  358. resources :mutes, only: [:index]
  359. resources :favourites, only: [:index]
  360. resources :bookmarks, only: [:index]
  361. resources :reports, only: [:create]
  362. resources :trends, only: [:index], controller: 'trends/tags'
  363. resources :filters, only: [:index, :create, :show, :update, :destroy] do
  364. resources :keywords, only: [:index, :create], controller: 'filters/keywords'
  365. end
  366. resources :endorsements, only: [:index]
  367. resources :markers, only: [:index, :create]
  368. namespace :filters do
  369. resources :keywords, only: [:show, :update, :destroy]
  370. end
  371. namespace :apps do
  372. get :verify_credentials, to: 'credentials#show'
  373. end
  374. resources :apps, only: [:create]
  375. namespace :trends do
  376. resources :links, only: [:index]
  377. resources :tags, only: [:index]
  378. resources :statuses, only: [:index]
  379. end
  380. namespace :emails do
  381. resources :confirmations, only: [:create]
  382. end
  383. resource :instance, only: [:show] do
  384. resources :peers, only: [:index], controller: 'instances/peers'
  385. resource :activity, only: [:show], controller: 'instances/activity'
  386. resources :rules, only: [:index], controller: 'instances/rules'
  387. end
  388. resource :domain_blocks, only: [:show, :create, :destroy]
  389. resource :directory, only: [:show]
  390. resources :follow_requests, only: [:index] do
  391. member do
  392. post :authorize
  393. post :reject
  394. end
  395. end
  396. resources :notifications, only: [:index, :show] do
  397. collection do
  398. post :clear
  399. end
  400. member do
  401. post :dismiss
  402. end
  403. end
  404. namespace :accounts do
  405. get :verify_credentials, to: 'credentials#show'
  406. patch :update_credentials, to: 'credentials#update'
  407. resource :search, only: :show, controller: :search
  408. resource :lookup, only: :show, controller: :lookup
  409. resources :relationships, only: :index
  410. resources :familiar_followers, only: :index
  411. end
  412. resources :accounts, only: [:create, :show] do
  413. resources :statuses, only: :index, controller: 'accounts/statuses'
  414. resources :followers, only: :index, controller: 'accounts/follower_accounts'
  415. resources :following, only: :index, controller: 'accounts/following_accounts'
  416. resources :lists, only: :index, controller: 'accounts/lists'
  417. resources :identity_proofs, only: :index, controller: 'accounts/identity_proofs'
  418. resources :featured_tags, only: :index, controller: 'accounts/featured_tags'
  419. member do
  420. post :follow
  421. post :unfollow
  422. post :remove_from_followers
  423. post :block
  424. post :unblock
  425. post :mute
  426. post :unmute
  427. end
  428. resource :pin, only: :create, controller: 'accounts/pins'
  429. post :unpin, to: 'accounts/pins#destroy'
  430. resource :note, only: :create, controller: 'accounts/notes'
  431. end
  432. resources :lists, only: [:index, :create, :show, :update, :destroy] do
  433. resource :accounts, only: [:show, :create, :destroy], controller: 'lists/accounts'
  434. end
  435. namespace :featured_tags do
  436. get :suggestions, to: 'suggestions#index'
  437. end
  438. resources :featured_tags, only: [:index, :create, :destroy]
  439. resources :polls, only: [:create, :show] do
  440. resources :votes, only: :create, controller: 'polls/votes'
  441. end
  442. namespace :push do
  443. resource :subscription, only: [:create, :show, :update, :destroy]
  444. end
  445. namespace :admin do
  446. resources :accounts, only: [:index, :show, :destroy] do
  447. member do
  448. post :enable
  449. post :unsensitive
  450. post :unsilence
  451. post :unsuspend
  452. post :approve
  453. post :reject
  454. end
  455. resource :action, only: [:create], controller: 'account_actions'
  456. end
  457. resources :reports, only: [:index, :update, :show] do
  458. member do
  459. post :assign_to_self
  460. post :unassign
  461. post :reopen
  462. post :resolve
  463. end
  464. end
  465. resources :domain_allows, only: [:index, :show, :create, :destroy]
  466. resources :domain_blocks, only: [:index, :show, :update, :create, :destroy]
  467. namespace :trends do
  468. resources :tags, only: [:index]
  469. resources :links, only: [:index]
  470. resources :statuses, only: [:index]
  471. end
  472. post :measures, to: 'measures#create'
  473. post :dimensions, to: 'dimensions#create'
  474. post :retention, to: 'retention#create'
  475. end
  476. end
  477. namespace :v2 do
  478. resources :media, only: [:create]
  479. get '/search', to: 'search#index', as: :search
  480. resources :suggestions, only: [:index]
  481. resources :filters, only: [:index, :create, :show, :update, :destroy]
  482. namespace :admin do
  483. resources :accounts, only: [:index]
  484. end
  485. end
  486. namespace :web do
  487. resource :settings, only: [:update]
  488. resource :embed, only: [:create]
  489. resources :push_subscriptions, only: [:create] do
  490. member do
  491. put :update
  492. end
  493. end
  494. end
  495. end
  496. get '/web/(*any)', to: 'home#index', as: :web
  497. get '/about', to: 'about#show'
  498. get '/about/more', to: 'about#more'
  499. get '/terms', to: 'about#terms'
  500. match '/', via: [:post, :put, :patch, :delete], to: 'application#raise_not_found', format: false
  501. match '*unmatched_route', via: :all, to: 'application#raise_not_found', format: false
  502. end