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