routes.rb 16 KB

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