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