Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

842 rindas
29KB

  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.Web.Router do
  5. use Pleroma.Web, :router
  6. pipeline :accepts_html do
  7. plug(:accepts, ["html"])
  8. end
  9. pipeline :accepts_html_xml do
  10. plug(:accepts, ["html", "xml", "rss", "atom"])
  11. end
  12. pipeline :accepts_html_json do
  13. plug(:accepts, ["html", "activity+json", "json"])
  14. end
  15. pipeline :accepts_html_xml_json do
  16. plug(:accepts, ["html", "xml", "rss", "atom", "activity+json", "json"])
  17. end
  18. pipeline :accepts_xml_rss_atom do
  19. plug(:accepts, ["xml", "rss", "atom"])
  20. end
  21. pipeline :browser do
  22. plug(:accepts, ["html"])
  23. plug(:fetch_session)
  24. end
  25. pipeline :oauth do
  26. plug(:fetch_session)
  27. plug(Pleroma.Web.Plugs.OAuthPlug)
  28. plug(Pleroma.Web.Plugs.UserEnabledPlug)
  29. plug(Pleroma.Web.Plugs.EnsureUserTokenAssignsPlug)
  30. end
  31. # Note: expects _user_ authentication (user-unbound app-bound tokens don't qualify)
  32. pipeline :expect_user_authentication do
  33. plug(Pleroma.Web.Plugs.ExpectAuthenticatedCheckPlug)
  34. end
  35. # Note: expects public instance or _user_ authentication (user-unbound tokens don't qualify)
  36. pipeline :expect_public_instance_or_user_authentication do
  37. plug(Pleroma.Web.Plugs.ExpectPublicOrAuthenticatedCheckPlug)
  38. end
  39. pipeline :authenticate do
  40. plug(Pleroma.Web.Plugs.OAuthPlug)
  41. plug(Pleroma.Web.Plugs.BasicAuthDecoderPlug)
  42. plug(Pleroma.Web.Plugs.UserFetcherPlug)
  43. plug(Pleroma.Web.Plugs.AuthenticationPlug)
  44. end
  45. pipeline :after_auth do
  46. plug(Pleroma.Web.Plugs.UserEnabledPlug)
  47. plug(Pleroma.Web.Plugs.SetUserSessionIdPlug)
  48. plug(Pleroma.Web.Plugs.EnsureUserTokenAssignsPlug)
  49. plug(Pleroma.Web.Plugs.UserTrackingPlug)
  50. end
  51. pipeline :base_api do
  52. plug(:accepts, ["json"])
  53. plug(:fetch_session)
  54. plug(:authenticate)
  55. plug(OpenApiSpex.Plug.PutApiSpec, module: Pleroma.Web.ApiSpec)
  56. end
  57. pipeline :no_auth_or_privacy_expectations_api do
  58. plug(:base_api)
  59. plug(:after_auth)
  60. plug(Pleroma.Web.Plugs.IdempotencyPlug)
  61. end
  62. # Pipeline for app-related endpoints (no user auth checks — app-bound tokens must be supported)
  63. pipeline :app_api do
  64. plug(:no_auth_or_privacy_expectations_api)
  65. end
  66. pipeline :api do
  67. plug(:expect_public_instance_or_user_authentication)
  68. plug(:no_auth_or_privacy_expectations_api)
  69. end
  70. pipeline :authenticated_api do
  71. plug(:expect_user_authentication)
  72. plug(:no_auth_or_privacy_expectations_api)
  73. plug(Pleroma.Web.Plugs.EnsureAuthenticatedPlug)
  74. end
  75. pipeline :admin_api do
  76. plug(:expect_user_authentication)
  77. plug(:base_api)
  78. plug(Pleroma.Web.Plugs.AdminSecretAuthenticationPlug)
  79. plug(:after_auth)
  80. plug(Pleroma.Web.Plugs.EnsureAuthenticatedPlug)
  81. plug(Pleroma.Web.Plugs.UserIsAdminPlug)
  82. plug(Pleroma.Web.Plugs.IdempotencyPlug)
  83. end
  84. pipeline :mastodon_html do
  85. plug(:browser)
  86. plug(:authenticate)
  87. plug(:after_auth)
  88. end
  89. pipeline :pleroma_html do
  90. plug(:browser)
  91. plug(:authenticate)
  92. plug(Pleroma.Web.Plugs.EnsureUserTokenAssignsPlug)
  93. end
  94. pipeline :well_known do
  95. plug(:accepts, ["json", "jrd+json", "xml", "xrd+xml"])
  96. end
  97. pipeline :config do
  98. plug(:accepts, ["json", "xml"])
  99. plug(OpenApiSpex.Plug.PutApiSpec, module: Pleroma.Web.ApiSpec)
  100. end
  101. pipeline :pleroma_api do
  102. plug(:accepts, ["html", "json"])
  103. plug(OpenApiSpex.Plug.PutApiSpec, module: Pleroma.Web.ApiSpec)
  104. end
  105. pipeline :mailbox_preview do
  106. plug(:accepts, ["html"])
  107. plug(:put_secure_browser_headers, %{
  108. "content-security-policy" =>
  109. "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline' 'unsafe-eval'"
  110. })
  111. end
  112. pipeline :http_signature do
  113. plug(Pleroma.Web.Plugs.HTTPSignaturePlug)
  114. plug(Pleroma.Web.Plugs.MappedSignatureToIdentityPlug)
  115. end
  116. pipeline :static_fe do
  117. plug(Pleroma.Web.Plugs.StaticFEPlug)
  118. end
  119. scope "/api/v1/pleroma", Pleroma.Web.TwitterAPI do
  120. pipe_through(:pleroma_api)
  121. get("/password_reset/:token", PasswordController, :reset, as: :reset_password)
  122. post("/password_reset", PasswordController, :do_reset, as: :reset_password)
  123. get("/emoji", UtilController, :emoji)
  124. get("/captcha", UtilController, :captcha)
  125. get("/healthcheck", UtilController, :healthcheck)
  126. end
  127. scope "/api/v1/pleroma", Pleroma.Web do
  128. pipe_through(:pleroma_api)
  129. post("/uploader_callback/:upload_path", UploaderController, :callback)
  130. end
  131. scope "/api/v1/pleroma/admin", Pleroma.Web.AdminAPI do
  132. pipe_through(:admin_api)
  133. put("/users/disable_mfa", AdminAPIController, :disable_mfa)
  134. put("/users/tag", AdminAPIController, :tag_users)
  135. delete("/users/tag", AdminAPIController, :untag_users)
  136. get("/users/:nickname/permission_group", AdminAPIController, :right_get)
  137. get("/users/:nickname/permission_group/:permission_group", AdminAPIController, :right_get)
  138. post("/users/:nickname/permission_group/:permission_group", AdminAPIController, :right_add)
  139. delete(
  140. "/users/:nickname/permission_group/:permission_group",
  141. AdminAPIController,
  142. :right_delete
  143. )
  144. post("/users/permission_group/:permission_group", AdminAPIController, :right_add_multiple)
  145. delete(
  146. "/users/permission_group/:permission_group",
  147. AdminAPIController,
  148. :right_delete_multiple
  149. )
  150. post("/users/follow", UserController, :follow)
  151. post("/users/unfollow", UserController, :unfollow)
  152. delete("/users", UserController, :delete)
  153. post("/users", UserController, :create)
  154. patch("/users/:nickname/toggle_activation", UserController, :toggle_activation)
  155. patch("/users/activate", UserController, :activate)
  156. patch("/users/deactivate", UserController, :deactivate)
  157. patch("/users/approve", UserController, :approve)
  158. get("/relay", RelayController, :index)
  159. post("/relay", RelayController, :follow)
  160. delete("/relay", RelayController, :unfollow)
  161. post("/users/invite_token", InviteController, :create)
  162. get("/users/invites", InviteController, :index)
  163. post("/users/revoke_invite", InviteController, :revoke)
  164. post("/users/email_invite", InviteController, :email)
  165. get("/users/:nickname/password_reset", AdminAPIController, :get_password_reset)
  166. patch("/users/force_password_reset", AdminAPIController, :force_password_reset)
  167. get("/users/:nickname/credentials", AdminAPIController, :show_user_credentials)
  168. patch("/users/:nickname/credentials", AdminAPIController, :update_user_credentials)
  169. get("/users", UserController, :index)
  170. get("/users/:nickname", UserController, :show)
  171. get("/users/:nickname/statuses", AdminAPIController, :list_user_statuses)
  172. get("/users/:nickname/chats", AdminAPIController, :list_user_chats)
  173. get("/instances/:instance/statuses", AdminAPIController, :list_instance_statuses)
  174. get("/instance_document/:name", InstanceDocumentController, :show)
  175. patch("/instance_document/:name", InstanceDocumentController, :update)
  176. delete("/instance_document/:name", InstanceDocumentController, :delete)
  177. patch("/users/confirm_email", AdminAPIController, :confirm_email)
  178. patch("/users/resend_confirmation_email", AdminAPIController, :resend_confirmation_email)
  179. get("/reports", ReportController, :index)
  180. get("/reports/:id", ReportController, :show)
  181. patch("/reports", ReportController, :update)
  182. post("/reports/:id/notes", ReportController, :notes_create)
  183. delete("/reports/:report_id/notes/:id", ReportController, :notes_delete)
  184. get("/statuses/:id", StatusController, :show)
  185. put("/statuses/:id", StatusController, :update)
  186. delete("/statuses/:id", StatusController, :delete)
  187. get("/statuses", StatusController, :index)
  188. get("/config", ConfigController, :show)
  189. post("/config", ConfigController, :update)
  190. get("/config/descriptions", ConfigController, :descriptions)
  191. get("/need_reboot", AdminAPIController, :need_reboot)
  192. get("/restart", AdminAPIController, :restart)
  193. get("/moderation_log", AdminAPIController, :list_log)
  194. post("/reload_emoji", AdminAPIController, :reload_emoji)
  195. get("/stats", AdminAPIController, :stats)
  196. get("/oauth_app", OAuthAppController, :index)
  197. post("/oauth_app", OAuthAppController, :create)
  198. patch("/oauth_app/:id", OAuthAppController, :update)
  199. delete("/oauth_app/:id", OAuthAppController, :delete)
  200. get("/media_proxy_caches", MediaProxyCacheController, :index)
  201. post("/media_proxy_caches/delete", MediaProxyCacheController, :delete)
  202. post("/media_proxy_caches/purge", MediaProxyCacheController, :purge)
  203. get("/chats/:id", ChatController, :show)
  204. get("/chats/:id/messages", ChatController, :messages)
  205. delete("/chats/:id/messages/:message_id", ChatController, :delete_message)
  206. get("/frontends", FrontendController, :index)
  207. post("/frontends/install", FrontendController, :install)
  208. post("/backups", AdminAPIController, :create_backup)
  209. end
  210. scope "/api/v1/pleroma/emoji", Pleroma.Web.PleromaAPI do
  211. scope "/pack" do
  212. pipe_through(:admin_api)
  213. post("/", EmojiPackController, :create)
  214. patch("/", EmojiPackController, :update)
  215. delete("/", EmojiPackController, :delete)
  216. end
  217. scope "/pack" do
  218. pipe_through(:api)
  219. get("/", EmojiPackController, :show)
  220. end
  221. # Modifying packs
  222. scope "/packs" do
  223. pipe_through(:admin_api)
  224. get("/import", EmojiPackController, :import_from_filesystem)
  225. get("/remote", EmojiPackController, :remote)
  226. post("/download", EmojiPackController, :download)
  227. post("/files", EmojiFileController, :create)
  228. patch("/files", EmojiFileController, :update)
  229. delete("/files", EmojiFileController, :delete)
  230. end
  231. # Pack info / downloading
  232. scope "/packs" do
  233. pipe_through(:api)
  234. get("/", EmojiPackController, :index)
  235. get("/archive", EmojiPackController, :archive)
  236. end
  237. end
  238. scope "/", Pleroma.Web.TwitterAPI do
  239. pipe_through(:pleroma_html)
  240. post("/main/ostatus", UtilController, :remote_subscribe)
  241. get("/ostatus_subscribe", RemoteFollowController, :follow)
  242. post("/ostatus_subscribe", RemoteFollowController, :do_follow)
  243. end
  244. scope "/api/pleroma", Pleroma.Web.TwitterAPI do
  245. pipe_through(:authenticated_api)
  246. post("/change_email", UtilController, :change_email)
  247. post("/change_password", UtilController, :change_password)
  248. post("/delete_account", UtilController, :delete_account)
  249. put("/notification_settings", UtilController, :update_notificaton_settings)
  250. post("/disable_account", UtilController, :disable_account)
  251. end
  252. scope "/api/pleroma", Pleroma.Web.PleromaAPI do
  253. pipe_through(:authenticated_api)
  254. post("/mutes_import", UserImportController, :mutes)
  255. post("/blocks_import", UserImportController, :blocks)
  256. post("/follow_import", UserImportController, :follow)
  257. get("/accounts/mfa", TwoFactorAuthenticationController, :settings)
  258. get("/accounts/mfa/backup_codes", TwoFactorAuthenticationController, :backup_codes)
  259. get("/accounts/mfa/setup/:method", TwoFactorAuthenticationController, :setup)
  260. post("/accounts/mfa/confirm/:method", TwoFactorAuthenticationController, :confirm)
  261. delete("/accounts/mfa/:method", TwoFactorAuthenticationController, :disable)
  262. end
  263. scope "/oauth", Pleroma.Web.OAuth do
  264. # Note: use /api/v1/accounts/verify_credentials for userinfo of signed-in user
  265. get("/registration_details", OAuthController, :registration_details)
  266. post("/mfa/verify", MFAController, :verify, as: :mfa_verify)
  267. get("/mfa", MFAController, :show)
  268. scope [] do
  269. pipe_through(:oauth)
  270. get("/authorize", OAuthController, :authorize)
  271. post("/authorize", OAuthController, :create_authorization)
  272. end
  273. scope [] do
  274. pipe_through(:fetch_session)
  275. post("/token", OAuthController, :token_exchange)
  276. post("/revoke", OAuthController, :token_revoke)
  277. post("/mfa/challenge", MFAController, :challenge)
  278. end
  279. scope [] do
  280. pipe_through(:browser)
  281. get("/prepare_request", OAuthController, :prepare_request)
  282. get("/:provider", OAuthController, :request)
  283. get("/:provider/callback", OAuthController, :callback)
  284. post("/register", OAuthController, :register)
  285. end
  286. end
  287. scope "/api/v1/pleroma", Pleroma.Web.PleromaAPI do
  288. pipe_through(:api)
  289. get("/statuses/:id/reactions/:emoji", EmojiReactionController, :index)
  290. get("/statuses/:id/reactions", EmojiReactionController, :index)
  291. end
  292. scope "/api/v0/pleroma", Pleroma.Web.PleromaAPI do
  293. pipe_through(:authenticated_api)
  294. get("/reports", ReportController, :index)
  295. get("/reports/:id", ReportController, :show)
  296. end
  297. scope "/api/v1/pleroma", Pleroma.Web.PleromaAPI do
  298. scope [] do
  299. pipe_through(:authenticated_api)
  300. post("/chats/by-account-id/:id", ChatController, :create)
  301. get("/chats", ChatController, :index)
  302. get("/chats/:id", ChatController, :show)
  303. get("/chats/:id/messages", ChatController, :messages)
  304. post("/chats/:id/messages", ChatController, :post_chat_message)
  305. delete("/chats/:id/messages/:message_id", ChatController, :delete_message)
  306. post("/chats/:id/read", ChatController, :mark_as_read)
  307. post("/chats/:id/messages/:message_id/read", ChatController, :mark_message_as_read)
  308. get("/conversations/:id/statuses", ConversationController, :statuses)
  309. get("/conversations/:id", ConversationController, :show)
  310. post("/conversations/read", ConversationController, :mark_as_read)
  311. patch("/conversations/:id", ConversationController, :update)
  312. put("/statuses/:id/reactions/:emoji", EmojiReactionController, :create)
  313. delete("/statuses/:id/reactions/:emoji", EmojiReactionController, :delete)
  314. post("/notifications/read", NotificationController, :mark_as_read)
  315. get("/mascot", MascotController, :show)
  316. put("/mascot", MascotController, :update)
  317. post("/scrobble", ScrobbleController, :create)
  318. get("/backups", BackupController, :index)
  319. post("/backups", BackupController, :create)
  320. end
  321. scope [] do
  322. pipe_through(:api)
  323. get("/accounts/:id/favourites", AccountController, :favourites)
  324. end
  325. scope [] do
  326. pipe_through(:authenticated_api)
  327. post("/accounts/:id/subscribe", AccountController, :subscribe)
  328. post("/accounts/:id/unsubscribe", AccountController, :unsubscribe)
  329. end
  330. post("/accounts/confirmation_resend", AccountController, :confirmation_resend)
  331. end
  332. scope "/api/v1/pleroma", Pleroma.Web.PleromaAPI do
  333. pipe_through(:api)
  334. get("/accounts/:id/scrobbles", ScrobbleController, :index)
  335. get("/federation_status", InstancesController, :show)
  336. end
  337. scope "/api/v2/pleroma", Pleroma.Web.PleromaAPI do
  338. scope [] do
  339. pipe_through(:authenticated_api)
  340. get("/chats", ChatController, :index2)
  341. end
  342. end
  343. scope "/api/v1", Pleroma.Web.MastodonAPI do
  344. pipe_through(:authenticated_api)
  345. get("/accounts/verify_credentials", AccountController, :verify_credentials)
  346. patch("/accounts/update_credentials", AccountController, :update_credentials)
  347. get("/accounts/relationships", AccountController, :relationships)
  348. get("/accounts/:id/lists", AccountController, :lists)
  349. get("/accounts/:id/identity_proofs", AccountController, :identity_proofs)
  350. get("/endorsements", AccountController, :endorsements)
  351. get("/blocks", AccountController, :blocks)
  352. get("/mutes", AccountController, :mutes)
  353. post("/follows", AccountController, :follow_by_uri)
  354. post("/accounts/:id/follow", AccountController, :follow)
  355. post("/accounts/:id/unfollow", AccountController, :unfollow)
  356. post("/accounts/:id/block", AccountController, :block)
  357. post("/accounts/:id/unblock", AccountController, :unblock)
  358. post("/accounts/:id/mute", AccountController, :mute)
  359. post("/accounts/:id/unmute", AccountController, :unmute)
  360. get("/conversations", ConversationController, :index)
  361. post("/conversations/:id/read", ConversationController, :mark_as_read)
  362. delete("/conversations/:id", ConversationController, :delete)
  363. get("/domain_blocks", DomainBlockController, :index)
  364. post("/domain_blocks", DomainBlockController, :create)
  365. delete("/domain_blocks", DomainBlockController, :delete)
  366. get("/filters", FilterController, :index)
  367. post("/filters", FilterController, :create)
  368. get("/filters/:id", FilterController, :show)
  369. put("/filters/:id", FilterController, :update)
  370. delete("/filters/:id", FilterController, :delete)
  371. get("/follow_requests", FollowRequestController, :index)
  372. post("/follow_requests/:id/authorize", FollowRequestController, :authorize)
  373. post("/follow_requests/:id/reject", FollowRequestController, :reject)
  374. get("/lists", ListController, :index)
  375. get("/lists/:id", ListController, :show)
  376. get("/lists/:id/accounts", ListController, :list_accounts)
  377. delete("/lists/:id", ListController, :delete)
  378. post("/lists", ListController, :create)
  379. put("/lists/:id", ListController, :update)
  380. post("/lists/:id/accounts", ListController, :add_to_list)
  381. delete("/lists/:id/accounts", ListController, :remove_from_list)
  382. get("/markers", MarkerController, :index)
  383. post("/markers", MarkerController, :upsert)
  384. post("/media", MediaController, :create)
  385. get("/media/:id", MediaController, :show)
  386. put("/media/:id", MediaController, :update)
  387. get("/notifications", NotificationController, :index)
  388. get("/notifications/:id", NotificationController, :show)
  389. post("/notifications/:id/dismiss", NotificationController, :dismiss)
  390. post("/notifications/clear", NotificationController, :clear)
  391. delete("/notifications/destroy_multiple", NotificationController, :destroy_multiple)
  392. # Deprecated: was removed in Mastodon v3, use `/notifications/:id/dismiss` instead
  393. post("/notifications/dismiss", NotificationController, :dismiss_via_body)
  394. post("/polls/:id/votes", PollController, :vote)
  395. post("/reports", ReportController, :create)
  396. get("/scheduled_statuses", ScheduledActivityController, :index)
  397. get("/scheduled_statuses/:id", ScheduledActivityController, :show)
  398. put("/scheduled_statuses/:id", ScheduledActivityController, :update)
  399. delete("/scheduled_statuses/:id", ScheduledActivityController, :delete)
  400. # Unlike `GET /api/v1/accounts/:id/favourites`, demands authentication
  401. get("/favourites", StatusController, :favourites)
  402. get("/bookmarks", StatusController, :bookmarks)
  403. post("/statuses", StatusController, :create)
  404. delete("/statuses/:id", StatusController, :delete)
  405. post("/statuses/:id/reblog", StatusController, :reblog)
  406. post("/statuses/:id/unreblog", StatusController, :unreblog)
  407. post("/statuses/:id/favourite", StatusController, :favourite)
  408. post("/statuses/:id/unfavourite", StatusController, :unfavourite)
  409. post("/statuses/:id/pin", StatusController, :pin)
  410. post("/statuses/:id/unpin", StatusController, :unpin)
  411. post("/statuses/:id/bookmark", StatusController, :bookmark)
  412. post("/statuses/:id/unbookmark", StatusController, :unbookmark)
  413. post("/statuses/:id/mute", StatusController, :mute_conversation)
  414. post("/statuses/:id/unmute", StatusController, :unmute_conversation)
  415. post("/push/subscription", SubscriptionController, :create)
  416. get("/push/subscription", SubscriptionController, :show)
  417. put("/push/subscription", SubscriptionController, :update)
  418. delete("/push/subscription", SubscriptionController, :delete)
  419. get("/suggestions", SuggestionController, :index)
  420. get("/timelines/home", TimelineController, :home)
  421. get("/timelines/direct", TimelineController, :direct)
  422. get("/timelines/list/:list_id", TimelineController, :list)
  423. end
  424. scope "/api/web", Pleroma.Web do
  425. pipe_through(:authenticated_api)
  426. # Backend-obscure settings blob for MastoFE, don't parse/reuse elsewhere
  427. put("/settings", MastoFEController, :put_settings)
  428. end
  429. scope "/api/v1", Pleroma.Web.MastodonAPI do
  430. pipe_through(:app_api)
  431. post("/apps", AppController, :create)
  432. get("/apps/verify_credentials", AppController, :verify_credentials)
  433. end
  434. scope "/api/v1", Pleroma.Web.MastodonAPI do
  435. pipe_through(:api)
  436. get("/accounts/search", SearchController, :account_search)
  437. get("/search", SearchController, :search)
  438. get("/accounts/:id/statuses", AccountController, :statuses)
  439. get("/accounts/:id/followers", AccountController, :followers)
  440. get("/accounts/:id/following", AccountController, :following)
  441. get("/accounts/:id", AccountController, :show)
  442. post("/accounts", AccountController, :create)
  443. get("/instance", InstanceController, :show)
  444. get("/instance/peers", InstanceController, :peers)
  445. get("/statuses", StatusController, :index)
  446. get("/statuses/:id", StatusController, :show)
  447. get("/statuses/:id/context", StatusController, :context)
  448. get("/statuses/:id/card", StatusController, :card)
  449. get("/statuses/:id/favourited_by", StatusController, :favourited_by)
  450. get("/statuses/:id/reblogged_by", StatusController, :reblogged_by)
  451. get("/custom_emojis", CustomEmojiController, :index)
  452. get("/trends", MastodonAPIController, :empty_array)
  453. get("/timelines/public", TimelineController, :public)
  454. get("/timelines/tag/:tag", TimelineController, :hashtag)
  455. get("/polls/:id", PollController, :show)
  456. end
  457. scope "/api/v2", Pleroma.Web.MastodonAPI do
  458. pipe_through(:api)
  459. get("/search", SearchController, :search2)
  460. post("/media", MediaController, :create2)
  461. end
  462. scope "/api", Pleroma.Web do
  463. pipe_through(:config)
  464. get("/pleroma/frontend_configurations", TwitterAPI.UtilController, :frontend_configurations)
  465. end
  466. scope "/api", Pleroma.Web do
  467. pipe_through(:api)
  468. get(
  469. "/account/confirm_email/:user_id/:token",
  470. TwitterAPI.Controller,
  471. :confirm_email,
  472. as: :confirm_email
  473. )
  474. end
  475. scope "/api" do
  476. pipe_through(:base_api)
  477. get("/openapi", OpenApiSpex.Plug.RenderSpec, [])
  478. end
  479. scope "/api", Pleroma.Web, as: :authenticated_twitter_api do
  480. pipe_through(:authenticated_api)
  481. get("/oauth_tokens", TwitterAPI.Controller, :oauth_tokens)
  482. delete("/oauth_tokens/:id", TwitterAPI.Controller, :revoke_token)
  483. post(
  484. "/qvitter/statuses/notifications/read",
  485. TwitterAPI.Controller,
  486. :mark_notifications_as_read
  487. )
  488. end
  489. scope "/", Pleroma.Web do
  490. # Note: html format is supported only if static FE is enabled
  491. # Note: http signature is only considered for json requests (no auth for non-json requests)
  492. pipe_through([:accepts_html_json, :http_signature, :static_fe])
  493. get("/objects/:uuid", OStatus.OStatusController, :object)
  494. get("/activities/:uuid", OStatus.OStatusController, :activity)
  495. get("/notice/:id", OStatus.OStatusController, :notice)
  496. # Mastodon compatibility routes
  497. get("/users/:nickname/statuses/:id", OStatus.OStatusController, :object)
  498. get("/users/:nickname/statuses/:id/activity", OStatus.OStatusController, :activity)
  499. end
  500. scope "/", Pleroma.Web do
  501. # Note: html format is supported only if static FE is enabled
  502. # Note: http signature is only considered for json requests (no auth for non-json requests)
  503. pipe_through([:accepts_html_xml_json, :http_signature, :static_fe])
  504. # Note: returns user _profile_ for json requests, redirects to user _feed_ for non-json ones
  505. get("/users/:nickname", Feed.UserController, :feed_redirect, as: :user_feed)
  506. end
  507. scope "/", Pleroma.Web do
  508. # Note: html format is supported only if static FE is enabled
  509. pipe_through([:accepts_html_xml, :static_fe])
  510. get("/users/:nickname/feed", Feed.UserController, :feed, as: :user_feed)
  511. end
  512. scope "/", Pleroma.Web do
  513. pipe_through(:accepts_html)
  514. get("/notice/:id/embed_player", OStatus.OStatusController, :notice_player)
  515. end
  516. scope "/", Pleroma.Web do
  517. pipe_through(:accepts_xml_rss_atom)
  518. get("/tags/:tag", Feed.TagController, :feed, as: :tag_feed)
  519. end
  520. scope "/", Pleroma.Web do
  521. pipe_through(:browser)
  522. get("/mailer/unsubscribe/:token", Mailer.SubscriptionController, :unsubscribe)
  523. end
  524. pipeline :ap_service_actor do
  525. plug(:accepts, ["activity+json", "json"])
  526. end
  527. # Server to Server (S2S) AP interactions
  528. pipeline :activitypub do
  529. plug(:ap_service_actor)
  530. plug(:http_signature)
  531. end
  532. # Client to Server (C2S) AP interactions
  533. pipeline :activitypub_client do
  534. plug(:ap_service_actor)
  535. plug(:fetch_session)
  536. plug(:authenticate)
  537. plug(:after_auth)
  538. end
  539. scope "/", Pleroma.Web.ActivityPub do
  540. pipe_through([:activitypub_client])
  541. get("/api/ap/whoami", ActivityPubController, :whoami)
  542. get("/users/:nickname/inbox", ActivityPubController, :read_inbox)
  543. get("/users/:nickname/outbox", ActivityPubController, :outbox)
  544. post("/users/:nickname/outbox", ActivityPubController, :update_outbox)
  545. post("/api/ap/upload_media", ActivityPubController, :upload_media)
  546. # The following two are S2S as well, see `ActivityPub.fetch_follow_information_for_user/1`:
  547. get("/users/:nickname/followers", ActivityPubController, :followers)
  548. get("/users/:nickname/following", ActivityPubController, :following)
  549. get("/users/:nickname/collections/featured", ActivityPubController, :pinned)
  550. end
  551. scope "/", Pleroma.Web.ActivityPub do
  552. pipe_through(:activitypub)
  553. post("/inbox", ActivityPubController, :inbox)
  554. post("/users/:nickname/inbox", ActivityPubController, :inbox)
  555. end
  556. scope "/relay", Pleroma.Web.ActivityPub do
  557. pipe_through(:ap_service_actor)
  558. get("/", ActivityPubController, :relay)
  559. scope [] do
  560. pipe_through(:http_signature)
  561. post("/inbox", ActivityPubController, :inbox)
  562. end
  563. get("/following", ActivityPubController, :relay_following)
  564. get("/followers", ActivityPubController, :relay_followers)
  565. end
  566. scope "/internal/fetch", Pleroma.Web.ActivityPub do
  567. pipe_through(:ap_service_actor)
  568. get("/", ActivityPubController, :internal_fetch)
  569. post("/inbox", ActivityPubController, :inbox)
  570. end
  571. scope "/.well-known", Pleroma.Web do
  572. pipe_through(:well_known)
  573. get("/host-meta", WebFinger.WebFingerController, :host_meta)
  574. get("/webfinger", WebFinger.WebFingerController, :webfinger)
  575. get("/nodeinfo", Nodeinfo.NodeinfoController, :schemas)
  576. end
  577. scope "/nodeinfo", Pleroma.Web do
  578. get("/:version", Nodeinfo.NodeinfoController, :nodeinfo)
  579. end
  580. scope "/", Pleroma.Web do
  581. pipe_through(:api)
  582. get("/web/manifest.json", MastoFEController, :manifest)
  583. end
  584. scope "/", Pleroma.Web do
  585. pipe_through(:mastodon_html)
  586. get("/web/login", MastodonAPI.AuthController, :login)
  587. delete("/auth/sign_out", MastodonAPI.AuthController, :logout)
  588. post("/auth/password", MastodonAPI.AuthController, :password_reset)
  589. get("/web/*path", MastoFEController, :index)
  590. get("/embed/:id", EmbedController, :show)
  591. end
  592. scope "/proxy/", Pleroma.Web do
  593. get("/preview/:sig/:url", MediaProxy.MediaProxyController, :preview)
  594. get("/preview/:sig/:url/:filename", MediaProxy.MediaProxyController, :preview)
  595. get("/:sig/:url", MediaProxy.MediaProxyController, :remote)
  596. get("/:sig/:url/:filename", MediaProxy.MediaProxyController, :remote)
  597. end
  598. if Pleroma.Config.get(:env) == :dev do
  599. scope "/dev" do
  600. pipe_through([:mailbox_preview])
  601. forward("/mailbox", Plug.Swoosh.MailboxPreview, base_path: "/dev/mailbox")
  602. end
  603. end
  604. # Test-only routes needed to test action dispatching and plug chain execution
  605. if Pleroma.Config.get(:env) == :test do
  606. @test_actions [
  607. :do_oauth_check,
  608. :fallback_oauth_check,
  609. :skip_oauth_check,
  610. :fallback_oauth_skip_publicity_check,
  611. :skip_oauth_skip_publicity_check,
  612. :missing_oauth_check_definition
  613. ]
  614. scope "/test/api", Pleroma.Tests do
  615. pipe_through(:api)
  616. for action <- @test_actions do
  617. get("/#{action}", AuthTestController, action)
  618. end
  619. end
  620. scope "/test/authenticated_api", Pleroma.Tests do
  621. pipe_through(:authenticated_api)
  622. for action <- @test_actions do
  623. get("/#{action}", AuthTestController, action)
  624. end
  625. end
  626. end
  627. scope "/", Pleroma.Web.MongooseIM do
  628. get("/user_exists", MongooseIMController, :user_exists)
  629. get("/check_password", MongooseIMController, :check_password)
  630. end
  631. scope "/", Pleroma.Web.Fallback do
  632. get("/registration/:token", RedirectController, :registration_page)
  633. get("/:maybe_nickname_or_id", RedirectController, :redirector_with_meta)
  634. match(:*, "/api/pleroma*path", LegacyPleromaApiRerouterPlug, [])
  635. get("/api*path", RedirectController, :api_not_implemented)
  636. get("/*path", RedirectController, :redirector_with_preload)
  637. options("/*path", RedirectController, :empty)
  638. end
  639. # TODO: Change to Phoenix.Router.routes/1 for Phoenix 1.6.0+
  640. def get_api_routes do
  641. __MODULE__.__routes__()
  642. |> Enum.reject(fn r -> r.plug == Pleroma.Web.Fallback.RedirectController end)
  643. |> Enum.map(fn r ->
  644. r.path
  645. |> String.split("/", trim: true)
  646. |> List.first()
  647. end)
  648. |> Enum.uniq()
  649. end
  650. end