routes.rb 17 KB

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