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