Merge branch 'chore/changelog' into 'develop'
[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/v1/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/v1/pleroma", Pleroma.Web do
154 pipe_through(:pleroma_api)
155 post("/uploader_callback/:upload_path", UploaderController, :callback)
156 end
157
158 scope "/api/v1/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, :index)
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/v1/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/v0/pleroma", Pleroma.Web.PleromaAPI do
372 pipe_through(:authenticated_api)
373 get("/reports", ReportController, :index)
374 get("/reports/:id", ReportController, :show)
375 end
376
377 scope "/api/v1/pleroma", Pleroma.Web.PleromaAPI do
378 scope [] do
379 pipe_through(:authenticated_api)
380
381 post("/chats/by-account-id/:id", ChatController, :create)
382 get("/chats", ChatController, :index)
383 get("/chats/:id", ChatController, :show)
384 get("/chats/:id/messages", ChatController, :messages)
385 post("/chats/:id/messages", ChatController, :post_chat_message)
386 delete("/chats/:id/messages/:message_id", ChatController, :delete_message)
387 post("/chats/:id/read", ChatController, :mark_as_read)
388 post("/chats/:id/messages/:message_id/read", ChatController, :mark_message_as_read)
389
390 get("/conversations/:id/statuses", ConversationController, :statuses)
391 get("/conversations/:id", ConversationController, :show)
392 post("/conversations/read", ConversationController, :mark_as_read)
393 patch("/conversations/:id", ConversationController, :update)
394
395 put("/statuses/:id/reactions/:emoji", EmojiReactionController, :create)
396 delete("/statuses/:id/reactions/:emoji", EmojiReactionController, :delete)
397 post("/notifications/read", NotificationController, :mark_as_read)
398
399 get("/mascot", MascotController, :show)
400 put("/mascot", MascotController, :update)
401
402 post("/scrobble", ScrobbleController, :create)
403
404 get("/backups", BackupController, :index)
405 post("/backups", BackupController, :create)
406 end
407
408 scope [] do
409 pipe_through(:api)
410 get("/accounts/:id/favourites", AccountController, :favourites)
411 end
412
413 scope [] do
414 pipe_through(:authenticated_api)
415
416 post("/accounts/:id/subscribe", AccountController, :subscribe)
417 post("/accounts/:id/unsubscribe", AccountController, :unsubscribe)
418 end
419
420 post("/accounts/confirmation_resend", AccountController, :confirmation_resend)
421 end
422
423 scope "/api/v1/pleroma", Pleroma.Web.PleromaAPI do
424 pipe_through(:api)
425 get("/accounts/:id/scrobbles", ScrobbleController, :index)
426 get("/federation_status", InstancesController, :show)
427 end
428
429 scope "/api/v2/pleroma", Pleroma.Web.PleromaAPI do
430 scope [] do
431 pipe_through(:authenticated_api)
432 get("/chats", ChatController, :index2)
433 end
434 end
435
436 scope "/api/v1", Pleroma.Web.MastodonAPI do
437 pipe_through(:authenticated_api)
438
439 get("/accounts/verify_credentials", AccountController, :verify_credentials)
440 patch("/accounts/update_credentials", AccountController, :update_credentials)
441
442 get("/accounts/relationships", AccountController, :relationships)
443 get("/accounts/:id/lists", AccountController, :lists)
444 get("/accounts/:id/identity_proofs", AccountController, :identity_proofs)
445 get("/endorsements", AccountController, :endorsements)
446 get("/blocks", AccountController, :blocks)
447 get("/mutes", AccountController, :mutes)
448
449 post("/follows", AccountController, :follow_by_uri)
450 post("/accounts/:id/follow", AccountController, :follow)
451 post("/accounts/:id/unfollow", AccountController, :unfollow)
452 post("/accounts/:id/block", AccountController, :block)
453 post("/accounts/:id/unblock", AccountController, :unblock)
454 post("/accounts/:id/mute", AccountController, :mute)
455 post("/accounts/:id/unmute", AccountController, :unmute)
456
457 get("/conversations", ConversationController, :index)
458 post("/conversations/:id/read", ConversationController, :mark_as_read)
459 delete("/conversations/:id", ConversationController, :delete)
460
461 get("/domain_blocks", DomainBlockController, :index)
462 post("/domain_blocks", DomainBlockController, :create)
463 delete("/domain_blocks", DomainBlockController, :delete)
464
465 get("/filters", FilterController, :index)
466
467 post("/filters", FilterController, :create)
468 get("/filters/:id", FilterController, :show)
469 put("/filters/:id", FilterController, :update)
470 delete("/filters/:id", FilterController, :delete)
471
472 get("/follow_requests", FollowRequestController, :index)
473 post("/follow_requests/:id/authorize", FollowRequestController, :authorize)
474 post("/follow_requests/:id/reject", FollowRequestController, :reject)
475
476 get("/lists", ListController, :index)
477 get("/lists/:id", ListController, :show)
478 get("/lists/:id/accounts", ListController, :list_accounts)
479
480 delete("/lists/:id", ListController, :delete)
481 post("/lists", ListController, :create)
482 put("/lists/:id", ListController, :update)
483 post("/lists/:id/accounts", ListController, :add_to_list)
484 delete("/lists/:id/accounts", ListController, :remove_from_list)
485
486 get("/markers", MarkerController, :index)
487 post("/markers", MarkerController, :upsert)
488
489 post("/media", MediaController, :create)
490 get("/media/:id", MediaController, :show)
491 put("/media/:id", MediaController, :update)
492
493 get("/notifications", NotificationController, :index)
494 get("/notifications/:id", NotificationController, :show)
495
496 post("/notifications/:id/dismiss", NotificationController, :dismiss)
497 post("/notifications/clear", NotificationController, :clear)
498 delete("/notifications/destroy_multiple", NotificationController, :destroy_multiple)
499 # Deprecated: was removed in Mastodon v3, use `/notifications/:id/dismiss` instead
500 post("/notifications/dismiss", NotificationController, :dismiss_via_body)
501
502 post("/polls/:id/votes", PollController, :vote)
503
504 post("/reports", ReportController, :create)
505
506 get("/scheduled_statuses", ScheduledActivityController, :index)
507 get("/scheduled_statuses/:id", ScheduledActivityController, :show)
508
509 put("/scheduled_statuses/:id", ScheduledActivityController, :update)
510 delete("/scheduled_statuses/:id", ScheduledActivityController, :delete)
511
512 # Unlike `GET /api/v1/accounts/:id/favourites`, demands authentication
513 get("/favourites", StatusController, :favourites)
514 get("/bookmarks", StatusController, :bookmarks)
515
516 post("/statuses", StatusController, :create)
517 delete("/statuses/:id", StatusController, :delete)
518 post("/statuses/:id/reblog", StatusController, :reblog)
519 post("/statuses/:id/unreblog", StatusController, :unreblog)
520 post("/statuses/:id/favourite", StatusController, :favourite)
521 post("/statuses/:id/unfavourite", StatusController, :unfavourite)
522 post("/statuses/:id/pin", StatusController, :pin)
523 post("/statuses/:id/unpin", StatusController, :unpin)
524 post("/statuses/:id/bookmark", StatusController, :bookmark)
525 post("/statuses/:id/unbookmark", StatusController, :unbookmark)
526 post("/statuses/:id/mute", StatusController, :mute_conversation)
527 post("/statuses/:id/unmute", StatusController, :unmute_conversation)
528
529 post("/push/subscription", SubscriptionController, :create)
530 get("/push/subscription", SubscriptionController, :show)
531 put("/push/subscription", SubscriptionController, :update)
532 delete("/push/subscription", SubscriptionController, :delete)
533
534 get("/suggestions", SuggestionController, :index)
535
536 get("/timelines/home", TimelineController, :home)
537 get("/timelines/direct", TimelineController, :direct)
538 get("/timelines/list/:list_id", TimelineController, :list)
539 end
540
541 scope "/api/web", Pleroma.Web do
542 pipe_through(:authenticated_api)
543
544 # Backend-obscure settings blob for MastoFE, don't parse/reuse elsewhere
545 put("/settings", MastoFEController, :put_settings)
546 end
547
548 scope "/api/v1", Pleroma.Web.MastodonAPI do
549 pipe_through(:app_api)
550
551 post("/apps", AppController, :create)
552 get("/apps/verify_credentials", AppController, :verify_credentials)
553 end
554
555 scope "/api/v1", Pleroma.Web.MastodonAPI do
556 pipe_through(:api)
557
558 get("/accounts/search", SearchController, :account_search)
559 get("/search", SearchController, :search)
560
561 get("/accounts/:id/statuses", AccountController, :statuses)
562 get("/accounts/:id/followers", AccountController, :followers)
563 get("/accounts/:id/following", AccountController, :following)
564 get("/accounts/:id", AccountController, :show)
565
566 post("/accounts", AccountController, :create)
567
568 get("/instance", InstanceController, :show)
569 get("/instance/peers", InstanceController, :peers)
570
571 get("/statuses", StatusController, :index)
572 get("/statuses/:id", StatusController, :show)
573 get("/statuses/:id/context", StatusController, :context)
574 get("/statuses/:id/card", StatusController, :card)
575 get("/statuses/:id/favourited_by", StatusController, :favourited_by)
576 get("/statuses/:id/reblogged_by", StatusController, :reblogged_by)
577
578 get("/custom_emojis", CustomEmojiController, :index)
579
580 get("/trends", MastodonAPIController, :empty_array)
581
582 get("/timelines/public", TimelineController, :public)
583 get("/timelines/tag/:tag", TimelineController, :hashtag)
584
585 get("/polls/:id", PollController, :show)
586 end
587
588 scope "/api/v2", Pleroma.Web.MastodonAPI do
589 pipe_through(:api)
590 get("/search", SearchController, :search2)
591
592 post("/media", MediaController, :create2)
593 end
594
595 scope "/api", Pleroma.Web do
596 pipe_through(:config)
597
598 get("/pleroma/frontend_configurations", TwitterAPI.UtilController, :frontend_configurations)
599 end
600
601 scope "/api", Pleroma.Web do
602 pipe_through(:api)
603
604 get(
605 "/account/confirm_email/:user_id/:token",
606 TwitterAPI.Controller,
607 :confirm_email,
608 as: :confirm_email
609 )
610 end
611
612 scope "/api" do
613 pipe_through(:base_api)
614
615 get("/openapi", OpenApiSpex.Plug.RenderSpec, [])
616 end
617
618 scope "/api", Pleroma.Web, as: :authenticated_twitter_api do
619 pipe_through(:authenticated_api)
620
621 get("/oauth_tokens", TwitterAPI.Controller, :oauth_tokens)
622 delete("/oauth_tokens/:id", TwitterAPI.Controller, :revoke_token)
623
624 post(
625 "/qvitter/statuses/notifications/read",
626 TwitterAPI.Controller,
627 :mark_notifications_as_read
628 )
629 end
630
631 scope "/", Pleroma.Web do
632 # Note: html format is supported only if static FE is enabled
633 # Note: http signature is only considered for json requests (no auth for non-json requests)
634 pipe_through([:accepts_html_json, :http_signature, Pleroma.Web.Plugs.StaticFEPlug])
635
636 get("/objects/:uuid", OStatus.OStatusController, :object)
637 get("/activities/:uuid", OStatus.OStatusController, :activity)
638 get("/notice/:id", OStatus.OStatusController, :notice)
639
640 # Mastodon compatibility routes
641 get("/users/:nickname/statuses/:id", OStatus.OStatusController, :object)
642 get("/users/:nickname/statuses/:id/activity", OStatus.OStatusController, :activity)
643 end
644
645 scope "/", Pleroma.Web do
646 # Note: html format is supported only if static FE is enabled
647 # Note: http signature is only considered for json requests (no auth for non-json requests)
648 pipe_through([:accepts_html_xml_json, :http_signature, Pleroma.Web.Plugs.StaticFEPlug])
649
650 # Note: returns user _profile_ for json requests, redirects to user _feed_ for non-json ones
651 get("/users/:nickname", Feed.UserController, :feed_redirect, as: :user_feed)
652 end
653
654 scope "/", Pleroma.Web do
655 # Note: html format is supported only if static FE is enabled
656 pipe_through([:accepts_html_xml, Pleroma.Web.Plugs.StaticFEPlug])
657
658 get("/users/:nickname/feed", Feed.UserController, :feed, as: :user_feed)
659 end
660
661 scope "/", Pleroma.Web do
662 pipe_through(:accepts_html)
663 get("/notice/:id/embed_player", OStatus.OStatusController, :notice_player)
664 end
665
666 scope "/", Pleroma.Web do
667 pipe_through(:accepts_xml_rss_atom)
668 get("/tags/:tag", Feed.TagController, :feed, as: :tag_feed)
669 end
670
671 scope "/", Pleroma.Web do
672 pipe_through(:browser)
673 get("/mailer/unsubscribe/:token", Mailer.SubscriptionController, :unsubscribe)
674 end
675
676 pipeline :ap_service_actor do
677 plug(:accepts, ["activity+json", "json"])
678 end
679
680 # Server to Server (S2S) AP interactions
681 pipeline :activitypub do
682 plug(:ap_service_actor)
683 plug(:http_signature)
684 end
685
686 # Client to Server (C2S) AP interactions
687 pipeline :activitypub_client do
688 plug(:ap_service_actor)
689 plug(:fetch_session)
690 plug(:authenticate)
691 plug(:after_auth)
692 end
693
694 scope "/", Pleroma.Web.ActivityPub do
695 pipe_through([:activitypub_client])
696
697 get("/api/ap/whoami", ActivityPubController, :whoami)
698 get("/users/:nickname/inbox", ActivityPubController, :read_inbox)
699
700 get("/users/:nickname/outbox", ActivityPubController, :outbox)
701 post("/users/:nickname/outbox", ActivityPubController, :update_outbox)
702 post("/api/ap/upload_media", ActivityPubController, :upload_media)
703
704 # The following two are S2S as well, see `ActivityPub.fetch_follow_information_for_user/1`:
705 get("/users/:nickname/followers", ActivityPubController, :followers)
706 get("/users/:nickname/following", ActivityPubController, :following)
707 get("/users/:nickname/collections/featured", ActivityPubController, :pinned)
708 end
709
710 scope "/", Pleroma.Web.ActivityPub do
711 pipe_through(:activitypub)
712 post("/inbox", ActivityPubController, :inbox)
713 post("/users/:nickname/inbox", ActivityPubController, :inbox)
714 end
715
716 scope "/relay", Pleroma.Web.ActivityPub do
717 pipe_through(:ap_service_actor)
718
719 get("/", ActivityPubController, :relay)
720
721 scope [] do
722 pipe_through(:http_signature)
723 post("/inbox", ActivityPubController, :inbox)
724 end
725
726 get("/following", ActivityPubController, :relay_following)
727 get("/followers", ActivityPubController, :relay_followers)
728 end
729
730 scope "/internal/fetch", Pleroma.Web.ActivityPub do
731 pipe_through(:ap_service_actor)
732
733 get("/", ActivityPubController, :internal_fetch)
734 post("/inbox", ActivityPubController, :inbox)
735 end
736
737 scope "/.well-known", Pleroma.Web do
738 pipe_through(:well_known)
739
740 get("/host-meta", WebFinger.WebFingerController, :host_meta)
741 get("/webfinger", WebFinger.WebFingerController, :webfinger)
742 get("/nodeinfo", Nodeinfo.NodeinfoController, :schemas)
743 end
744
745 scope "/nodeinfo", Pleroma.Web do
746 get("/:version", Nodeinfo.NodeinfoController, :nodeinfo)
747 end
748
749 scope "/", Pleroma.Web do
750 pipe_through(:api)
751
752 get("/web/manifest.json", MastoFEController, :manifest)
753 end
754
755 scope "/", Pleroma.Web do
756 pipe_through(:mastodon_html)
757
758 get("/web/login", MastodonAPI.AuthController, :login)
759 delete("/auth/sign_out", MastodonAPI.AuthController, :logout)
760
761 post("/auth/password", MastodonAPI.AuthController, :password_reset)
762
763 get("/web/*path", MastoFEController, :index)
764
765 get("/embed/:id", EmbedController, :show)
766 end
767
768 scope "/proxy/", Pleroma.Web.MediaProxy do
769 get("/preview/:sig/:url", MediaProxyController, :preview)
770 get("/preview/:sig/:url/:filename", MediaProxyController, :preview)
771 get("/:sig/:url", MediaProxyController, :remote)
772 get("/:sig/:url/:filename", MediaProxyController, :remote)
773 end
774
775 if Pleroma.Config.get(:env) == :dev do
776 scope "/dev" do
777 pipe_through([:mailbox_preview])
778
779 forward("/mailbox", Plug.Swoosh.MailboxPreview, base_path: "/dev/mailbox")
780 end
781 end
782
783 # Test-only routes needed to test action dispatching and plug chain execution
784 if Pleroma.Config.get(:env) == :test do
785 @test_actions [
786 :do_oauth_check,
787 :fallback_oauth_check,
788 :skip_oauth_check,
789 :fallback_oauth_skip_publicity_check,
790 :skip_oauth_skip_publicity_check,
791 :missing_oauth_check_definition
792 ]
793
794 scope "/test/api", Pleroma.Tests do
795 pipe_through(:api)
796
797 for action <- @test_actions do
798 get("/#{action}", AuthTestController, action)
799 end
800 end
801
802 scope "/test/authenticated_api", Pleroma.Tests do
803 pipe_through(:authenticated_api)
804
805 for action <- @test_actions do
806 get("/#{action}", AuthTestController, action)
807 end
808 end
809 end
810
811 scope "/", Pleroma.Web.MongooseIM do
812 get("/user_exists", MongooseIMController, :user_exists)
813 get("/check_password", MongooseIMController, :check_password)
814 end
815
816 scope "/", Pleroma.Web.Fallback do
817 get("/registration/:token", RedirectController, :registration_page)
818 get("/:maybe_nickname_or_id", RedirectController, :redirector_with_meta)
819 match(:*, "/api/pleroma*path", LegacyPleromaApiRerouterPlug, [])
820 get("/api*path", RedirectController, :api_not_implemented)
821 get("/*path", RedirectController, :redirector_with_preload)
822
823 options("/*path", RedirectController, :empty)
824 end
825 end