routes.rb 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481
  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. 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. 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. resources :collections, only: [:show], module: :activitypub
  63. end
  64. resource :inbox, only: [:create], module: :activitypub
  65. get '/@:username', to: 'accounts#show', as: :short_account
  66. get '/@:username/with_replies', to: 'accounts#show', as: :short_account_with_replies
  67. get '/@:username/media', to: 'accounts#show', as: :short_account_media
  68. get '/@:username/tagged/:tag', to: 'accounts#show', as: :short_account_tag
  69. get '/@:account_username/:id', to: 'statuses#show', as: :short_account_status
  70. get '/@:account_username/:id/embed', to: 'statuses#embed', as: :embed_short_account_status
  71. get '/interact/:id', to: 'remote_interaction#new', as: :remote_interaction
  72. post '/interact/:id', to: 'remote_interaction#create'
  73. get '/explore', to: 'directories#index', as: :explore
  74. get '/explore/:id', to: 'directories#show', as: :explore_hashtag
  75. get '/settings', to: redirect('/settings/profile')
  76. namespace :settings do
  77. resource :profile, only: [:show, :update]
  78. get :preferences, to: redirect('/settings/preferences/appearance')
  79. namespace :preferences do
  80. resource :appearance, only: [:show, :update], controller: :appearance
  81. resource :notifications, only: [:show, :update]
  82. resource :other, only: [:show, :update], controller: :other
  83. end
  84. resource :import, only: [:show, :create]
  85. resource :export, only: [:show, :create]
  86. namespace :exports, constraints: { format: :csv } do
  87. resources :follows, only: :index, controller: :following_accounts
  88. resources :blocks, only: :index, controller: :blocked_accounts
  89. resources :mutes, only: :index, controller: :muted_accounts
  90. resources :lists, only: :index, controller: :lists
  91. resources :domain_blocks, only: :index, controller: :blocked_domains
  92. end
  93. resource :two_factor_authentication, only: [:show, :create, :destroy]
  94. namespace :two_factor_authentication do
  95. resources :recovery_codes, only: [:create]
  96. resource :confirmation, only: [:new, :create]
  97. end
  98. resources :identity_proofs, only: [:index, :show, :new, :create, :update]
  99. resources :applications, except: [:edit] do
  100. member do
  101. post :regenerate
  102. end
  103. end
  104. resource :delete, only: [:show, :destroy]
  105. resource :migration, only: [:show, :create]
  106. namespace :migration do
  107. resource :redirect, only: [:new, :create, :destroy]
  108. end
  109. resources :aliases, only: [:index, :create, :destroy]
  110. resources :sessions, only: [:destroy]
  111. resources :featured_tags, only: [:index, :create, :destroy]
  112. end
  113. resources :media, only: [:show] do
  114. get :player
  115. end
  116. resources :tags, only: [:show]
  117. resources :emojis, only: [:show]
  118. resources :invites, only: [:index, :create, :destroy]
  119. resources :filters, except: [:show]
  120. resource :relationships, only: [:show, :update]
  121. get '/public', to: 'public_timelines#show', as: :public_timeline
  122. get '/media_proxy/:id/(*any)', to: 'media_proxy#show', as: :media_proxy
  123. resource :authorize_interaction, only: [:show, :create]
  124. resource :share, only: [:show, :create]
  125. namespace :admin do
  126. get '/dashboard', to: 'dashboard#index'
  127. resources :domain_allows, only: [:new, :create, :show, :destroy]
  128. resources :domain_blocks, only: [:new, :create, :show, :destroy, :update] do
  129. member do
  130. get :edit
  131. end
  132. end
  133. resources :email_domain_blocks, only: [:index, :new, :create, :destroy]
  134. resources :action_logs, only: [:index]
  135. resources :warning_presets, except: [:new]
  136. resources :announcements, except: [:show] do
  137. member do
  138. post :publish
  139. post :unpublish
  140. end
  141. end
  142. resource :settings, only: [:edit, :update]
  143. resources :site_uploads, only: [:destroy]
  144. resources :invites, only: [:index, :create, :destroy] do
  145. collection do
  146. post :deactivate_all
  147. end
  148. end
  149. resources :relays, only: [:index, :new, :create, :destroy] do
  150. member do
  151. post :enable
  152. post :disable
  153. end
  154. end
  155. resources :instances, only: [:index, :show], constraints: { id: /[^\/]+/ }
  156. resources :reports, only: [:index, :show] do
  157. member do
  158. post :assign_to_self
  159. post :unassign
  160. post :reopen
  161. post :resolve
  162. end
  163. resources :reported_statuses, only: [:create]
  164. end
  165. resources :report_notes, only: [:create, :destroy]
  166. resources :accounts, only: [:index, :show] do
  167. member do
  168. post :enable
  169. post :unsilence
  170. post :unsuspend
  171. post :redownload
  172. post :remove_avatar
  173. post :remove_header
  174. post :memorialize
  175. post :approve
  176. post :reject
  177. end
  178. resource :change_email, only: [:show, :update]
  179. resource :reset, only: [:create]
  180. resource :action, only: [:new, :create], controller: 'account_actions'
  181. resources :statuses, only: [:index, :show, :create, :update, :destroy]
  182. resources :relationships, only: [:index]
  183. resource :confirmation, only: [:create] do
  184. collection do
  185. post :resend
  186. end
  187. end
  188. resource :role, only: [] do
  189. member do
  190. post :promote
  191. post :demote
  192. end
  193. end
  194. end
  195. resources :pending_accounts, only: [:index] do
  196. collection do
  197. post :approve_all
  198. post :reject_all
  199. post :batch
  200. end
  201. end
  202. resources :users, only: [] do
  203. resource :two_factor_authentication, only: [:destroy]
  204. end
  205. resources :custom_emojis, only: [:index, :new, :create] do
  206. collection do
  207. post :batch
  208. end
  209. end
  210. resources :account_moderation_notes, only: [:create, :destroy]
  211. resources :tags, only: [:index, :show, :update] do
  212. collection do
  213. post :approve_all
  214. post :reject_all
  215. post :batch
  216. end
  217. end
  218. end
  219. get '/admin', to: redirect('/admin/dashboard', status: 302)
  220. namespace :api do
  221. # OEmbed
  222. get '/oembed', to: 'oembed#show', as: :oembed
  223. # Identity proofs
  224. get :proofs, to: 'proofs#index'
  225. # JSON / REST API
  226. namespace :v1 do
  227. resources :statuses, only: [:create, :show, :destroy] do
  228. scope module: :statuses do
  229. resources :reblogged_by, controller: :reblogged_by_accounts, only: :index
  230. resources :favourited_by, controller: :favourited_by_accounts, only: :index
  231. resource :reblog, only: :create
  232. post :unreblog, to: 'reblogs#destroy'
  233. resource :favourite, only: :create
  234. post :unfavourite, to: 'favourites#destroy'
  235. resource :bookmark, only: :create
  236. post :unbookmark, to: 'bookmarks#destroy'
  237. resource :mute, only: :create
  238. post :unmute, to: 'mutes#destroy'
  239. resource :pin, only: :create
  240. post :unpin, to: 'pins#destroy'
  241. end
  242. member do
  243. get :context
  244. end
  245. end
  246. namespace :timelines do
  247. resource :home, only: :show, controller: :home
  248. resource :public, only: :show, controller: :public
  249. resources :tag, only: :show
  250. resources :list, only: :show
  251. end
  252. resources :streaming, only: [:index]
  253. resources :custom_emojis, only: [:index]
  254. resources :suggestions, only: [:index, :destroy]
  255. resources :scheduled_statuses, only: [:index, :show, :update, :destroy]
  256. resources :preferences, only: [:index]
  257. resources :announcements, only: [:index] do
  258. scope module: :announcements do
  259. resources :reactions, only: [:update, :destroy]
  260. end
  261. member do
  262. post :dismiss
  263. end
  264. end
  265. resources :conversations, only: [:index, :destroy] do
  266. member do
  267. post :read
  268. end
  269. end
  270. resources :media, only: [:create, :update, :show]
  271. resources :blocks, only: [:index]
  272. resources :mutes, only: [:index]
  273. resources :favourites, only: [:index]
  274. resources :bookmarks, only: [:index]
  275. resources :reports, only: [:create]
  276. resources :trends, only: [:index]
  277. resources :filters, only: [:index, :create, :show, :update, :destroy]
  278. resources :endorsements, only: [:index]
  279. resources :markers, only: [:index, :create]
  280. namespace :apps do
  281. get :verify_credentials, to: 'credentials#show'
  282. end
  283. resources :apps, only: [:create]
  284. resource :instance, only: [:show] do
  285. resources :peers, only: [:index], controller: 'instances/peers'
  286. resource :activity, only: [:show], controller: 'instances/activity'
  287. end
  288. resource :domain_blocks, only: [:show, :create, :destroy]
  289. resource :directory, only: [:show]
  290. resources :follow_requests, only: [:index] do
  291. member do
  292. post :authorize
  293. post :reject
  294. end
  295. end
  296. resources :notifications, only: [:index, :show] do
  297. collection do
  298. post :clear
  299. end
  300. member do
  301. post :dismiss
  302. end
  303. end
  304. namespace :accounts do
  305. get :verify_credentials, to: 'credentials#show'
  306. patch :update_credentials, to: 'credentials#update'
  307. resource :search, only: :show, controller: :search
  308. resources :relationships, only: :index
  309. end
  310. resources :accounts, only: [:create, :show] do
  311. resources :statuses, only: :index, controller: 'accounts/statuses'
  312. resources :followers, only: :index, controller: 'accounts/follower_accounts'
  313. resources :following, only: :index, controller: 'accounts/following_accounts'
  314. resources :lists, only: :index, controller: 'accounts/lists'
  315. resources :identity_proofs, only: :index, controller: 'accounts/identity_proofs'
  316. member do
  317. post :follow
  318. post :unfollow
  319. post :block
  320. post :unblock
  321. post :mute
  322. post :unmute
  323. end
  324. resource :pin, only: :create, controller: 'accounts/pins'
  325. post :unpin, to: 'accounts/pins#destroy'
  326. end
  327. resources :lists, only: [:index, :create, :show, :update, :destroy] do
  328. resource :accounts, only: [:show, :create, :destroy], controller: 'lists/accounts'
  329. end
  330. namespace :featured_tags do
  331. get :suggestions, to: 'suggestions#index'
  332. end
  333. resources :featured_tags, only: [:index, :create, :destroy]
  334. resources :polls, only: [:create, :show] do
  335. resources :votes, only: :create, controller: 'polls/votes'
  336. end
  337. namespace :push do
  338. resource :subscription, only: [:create, :show, :update, :destroy]
  339. end
  340. namespace :admin do
  341. resources :accounts, only: [:index, :show] do
  342. member do
  343. post :enable
  344. post :unsilence
  345. post :unsuspend
  346. post :approve
  347. post :reject
  348. end
  349. resource :action, only: [:create], controller: 'account_actions'
  350. end
  351. resources :reports, only: [:index, :show] do
  352. member do
  353. post :assign_to_self
  354. post :unassign
  355. post :reopen
  356. post :resolve
  357. end
  358. end
  359. end
  360. end
  361. namespace :v2 do
  362. resources :media, only: [:create]
  363. get '/search', to: 'search#index', as: :search
  364. end
  365. namespace :web do
  366. resource :settings, only: [:update]
  367. resource :embed, only: [:create]
  368. resources :push_subscriptions, only: [:create] do
  369. member do
  370. put :update
  371. end
  372. end
  373. end
  374. end
  375. get '/web/(*any)', to: 'home#index', as: :web
  376. get '/about', to: 'about#show'
  377. get '/about/more', to: 'about#more'
  378. get '/terms', to: 'about#terms'
  379. match '/', via: [:post, :put, :patch, :delete], to: 'application#raise_not_found', format: false
  380. match '*unmatched_route', via: :all, to: 'application#raise_not_found', format: false
  381. end