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