logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

router.ex (36308B)


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