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