559d3aa0c280c848df8cd75171c8c4978ca402ed
[akkoma] / lib / pleroma / web / router.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 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 :api do
9 plug(:accepts, ["json"])
10 plug(:fetch_session)
11 plug(Pleroma.Plugs.OAuthPlug)
12 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
13 plug(Pleroma.Plugs.UserFetcherPlug)
14 plug(Pleroma.Plugs.SessionAuthenticationPlug)
15 plug(Pleroma.Plugs.LegacyAuthenticationPlug)
16 plug(Pleroma.Plugs.AuthenticationPlug)
17 plug(Pleroma.Plugs.UserEnabledPlug)
18 plug(Pleroma.Plugs.SetUserSessionIdPlug)
19 plug(Pleroma.Plugs.EnsureUserKeyPlug)
20 end
21
22 pipeline :authenticated_api do
23 plug(:accepts, ["json"])
24 plug(:fetch_session)
25 plug(Pleroma.Plugs.OAuthPlug)
26 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
27 plug(Pleroma.Plugs.UserFetcherPlug)
28 plug(Pleroma.Plugs.SessionAuthenticationPlug)
29 plug(Pleroma.Plugs.LegacyAuthenticationPlug)
30 plug(Pleroma.Plugs.AuthenticationPlug)
31 plug(Pleroma.Plugs.UserEnabledPlug)
32 plug(Pleroma.Plugs.SetUserSessionIdPlug)
33 plug(Pleroma.Plugs.EnsureAuthenticatedPlug)
34 end
35
36 pipeline :admin_api do
37 plug(:accepts, ["json"])
38 plug(:fetch_session)
39 plug(Pleroma.Plugs.OAuthPlug)
40 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
41 plug(Pleroma.Plugs.UserFetcherPlug)
42 plug(Pleroma.Plugs.SessionAuthenticationPlug)
43 plug(Pleroma.Plugs.LegacyAuthenticationPlug)
44 plug(Pleroma.Plugs.AuthenticationPlug)
45 plug(Pleroma.Plugs.AdminSecretAuthenticationPlug)
46 plug(Pleroma.Plugs.UserEnabledPlug)
47 plug(Pleroma.Plugs.SetUserSessionIdPlug)
48 plug(Pleroma.Plugs.EnsureAuthenticatedPlug)
49 plug(Pleroma.Plugs.UserIsAdminPlug)
50 end
51
52 pipeline :mastodon_html do
53 plug(:accepts, ["html"])
54 plug(:fetch_session)
55 plug(Pleroma.Plugs.OAuthPlug)
56 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
57 plug(Pleroma.Plugs.UserFetcherPlug)
58 plug(Pleroma.Plugs.SessionAuthenticationPlug)
59 plug(Pleroma.Plugs.LegacyAuthenticationPlug)
60 plug(Pleroma.Plugs.AuthenticationPlug)
61 plug(Pleroma.Plugs.UserEnabledPlug)
62 plug(Pleroma.Plugs.SetUserSessionIdPlug)
63 plug(Pleroma.Plugs.EnsureUserKeyPlug)
64 end
65
66 pipeline :pleroma_html do
67 plug(:accepts, ["html"])
68 plug(:fetch_session)
69 plug(Pleroma.Plugs.OAuthPlug)
70 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
71 plug(Pleroma.Plugs.UserFetcherPlug)
72 plug(Pleroma.Plugs.SessionAuthenticationPlug)
73 plug(Pleroma.Plugs.AuthenticationPlug)
74 plug(Pleroma.Plugs.EnsureUserKeyPlug)
75 end
76
77 pipeline :oauth_read_or_unauthenticated do
78 plug(Pleroma.Plugs.OAuthScopesPlug, %{
79 scopes: ["read"],
80 fallback: :proceed_unauthenticated
81 })
82 end
83
84 pipeline :oauth_read do
85 plug(Pleroma.Plugs.OAuthScopesPlug, %{scopes: ["read"]})
86 end
87
88 pipeline :oauth_write do
89 plug(Pleroma.Plugs.OAuthScopesPlug, %{scopes: ["write"]})
90 end
91
92 pipeline :oauth_follow do
93 plug(Pleroma.Plugs.OAuthScopesPlug, %{scopes: ["follow"]})
94 end
95
96 pipeline :oauth_push do
97 plug(Pleroma.Plugs.OAuthScopesPlug, %{scopes: ["push"]})
98 end
99
100 pipeline :well_known do
101 plug(:accepts, ["json", "jrd+json", "xml", "xrd+xml"])
102 end
103
104 pipeline :config do
105 plug(:accepts, ["json", "xml"])
106 end
107
108 pipeline :oauth do
109 plug(:accepts, ["html", "json"])
110 end
111
112 pipeline :pleroma_api do
113 plug(:accepts, ["html", "json"])
114 end
115
116 pipeline :mailbox_preview do
117 plug(:accepts, ["html"])
118
119 plug(:put_secure_browser_headers, %{
120 "content-security-policy" =>
121 "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline' 'unsafe-eval'"
122 })
123 end
124
125 scope "/api/pleroma", Pleroma.Web.TwitterAPI do
126 pipe_through(:pleroma_api)
127
128 get("/password_reset/:token", UtilController, :show_password_reset)
129 post("/password_reset", UtilController, :password_reset)
130 get("/emoji", UtilController, :emoji)
131 get("/captcha", UtilController, :captcha)
132 end
133
134 scope "/api/pleroma", Pleroma.Web do
135 pipe_through(:pleroma_api)
136 post("/uploader_callback/:upload_path", UploaderController, :callback)
137 end
138
139 scope "/api/pleroma/admin", Pleroma.Web.AdminAPI do
140 pipe_through([:admin_api, :oauth_write])
141
142 delete("/user", AdminAPIController, :user_delete)
143 post("/user", AdminAPIController, :user_create)
144 put("/users/tag", AdminAPIController, :tag_users)
145 delete("/users/tag", AdminAPIController, :untag_users)
146
147 get("/permission_group/:nickname", AdminAPIController, :right_get)
148 get("/permission_group/:nickname/:permission_group", AdminAPIController, :right_get)
149 post("/permission_group/:nickname/:permission_group", AdminAPIController, :right_add)
150 delete("/permission_group/:nickname/:permission_group", AdminAPIController, :right_delete)
151
152 put("/activation_status/:nickname", AdminAPIController, :set_activation_status)
153
154 post("/relay", AdminAPIController, :relay_follow)
155 delete("/relay", AdminAPIController, :relay_unfollow)
156
157 get("/invite_token", AdminAPIController, :get_invite_token)
158 post("/email_invite", AdminAPIController, :email_invite)
159
160 get("/password_reset", AdminAPIController, :get_password_reset)
161 end
162
163 scope "/", Pleroma.Web.TwitterAPI do
164 pipe_through(:pleroma_html)
165
166 post("/main/ostatus", UtilController, :remote_subscribe)
167 get("/ostatus_subscribe", UtilController, :remote_follow)
168
169 scope [] do
170 pipe_through(:oauth_follow)
171 post("/ostatus_subscribe", UtilController, :do_remote_follow)
172 end
173 end
174
175 scope "/api/pleroma", Pleroma.Web.TwitterAPI do
176 pipe_through(:authenticated_api)
177
178 scope [] do
179 pipe_through(:oauth_write)
180
181 post("/change_password", UtilController, :change_password)
182 post("/delete_account", UtilController, :delete_account)
183 end
184
185 scope [] do
186 pipe_through(:oauth_follow)
187
188 post("/blocks_import", UtilController, :blocks_import)
189 post("/follow_import", UtilController, :follow_import)
190 end
191 end
192
193 scope "/oauth", Pleroma.Web.OAuth do
194 get("/authorize", OAuthController, :authorize)
195 post("/authorize", OAuthController, :create_authorization)
196 post("/token", OAuthController, :token_exchange)
197 post("/revoke", OAuthController, :token_revoke)
198 end
199
200 scope "/api/v1", Pleroma.Web.MastodonAPI do
201 pipe_through(:authenticated_api)
202
203 scope [] do
204 pipe_through(:oauth_read)
205
206 get("/accounts/verify_credentials", MastodonAPIController, :verify_credentials)
207
208 get("/accounts/relationships", MastodonAPIController, :relationships)
209 get("/accounts/search", MastodonAPIController, :account_search)
210
211 get("/accounts/:id/lists", MastodonAPIController, :account_lists)
212
213 get("/follow_requests", MastodonAPIController, :follow_requests)
214 get("/blocks", MastodonAPIController, :blocks)
215 get("/mutes", MastodonAPIController, :mutes)
216
217 get("/timelines/home", MastodonAPIController, :home_timeline)
218 get("/timelines/direct", MastodonAPIController, :dm_timeline)
219
220 get("/favourites", MastodonAPIController, :favourites)
221 get("/bookmarks", MastodonAPIController, :bookmarks)
222
223 post("/notifications/clear", MastodonAPIController, :clear_notifications)
224 post("/notifications/dismiss", MastodonAPIController, :dismiss_notification)
225 get("/notifications", MastodonAPIController, :notifications)
226 get("/notifications/:id", MastodonAPIController, :get_notification)
227
228 get("/lists", MastodonAPIController, :get_lists)
229 get("/lists/:id", MastodonAPIController, :get_list)
230 get("/lists/:id/accounts", MastodonAPIController, :list_accounts)
231
232 get("/domain_blocks", MastodonAPIController, :domain_blocks)
233
234 get("/filters", MastodonAPIController, :get_filters)
235
236 get("/suggestions", MastodonAPIController, :suggestions)
237
238 get("/endorsements", MastodonAPIController, :empty_array)
239
240 get("/pleroma/flavour", MastodonAPIController, :get_flavour)
241 end
242
243 scope [] do
244 pipe_through(:oauth_write)
245
246 patch("/accounts/update_credentials", MastodonAPIController, :update_credentials)
247
248 post("/statuses", MastodonAPIController, :post_status)
249 delete("/statuses/:id", MastodonAPIController, :delete_status)
250
251 post("/statuses/:id/reblog", MastodonAPIController, :reblog_status)
252 post("/statuses/:id/unreblog", MastodonAPIController, :unreblog_status)
253 post("/statuses/:id/favourite", MastodonAPIController, :fav_status)
254 post("/statuses/:id/unfavourite", MastodonAPIController, :unfav_status)
255 post("/statuses/:id/pin", MastodonAPIController, :pin_status)
256 post("/statuses/:id/unpin", MastodonAPIController, :unpin_status)
257 post("/statuses/:id/bookmark", MastodonAPIController, :bookmark_status)
258 post("/statuses/:id/unbookmark", MastodonAPIController, :unbookmark_status)
259 post("/statuses/:id/mute", MastodonAPIController, :mute_conversation)
260 post("/statuses/:id/unmute", MastodonAPIController, :unmute_conversation)
261
262 post("/media", MastodonAPIController, :upload)
263 put("/media/:id", MastodonAPIController, :update_media)
264
265 delete("/lists/:id", MastodonAPIController, :delete_list)
266 post("/lists", MastodonAPIController, :create_list)
267 put("/lists/:id", MastodonAPIController, :rename_list)
268
269 post("/lists/:id/accounts", MastodonAPIController, :add_to_list)
270 delete("/lists/:id/accounts", MastodonAPIController, :remove_from_list)
271
272 post("/filters", MastodonAPIController, :create_filter)
273 get("/filters/:id", MastodonAPIController, :get_filter)
274 put("/filters/:id", MastodonAPIController, :update_filter)
275 delete("/filters/:id", MastodonAPIController, :delete_filter)
276
277 post("/pleroma/flavour/:flavour", MastodonAPIController, :set_flavour)
278 end
279
280 scope [] do
281 pipe_through(:oauth_follow)
282
283 post("/follows", MastodonAPIController, :follow)
284 post("/accounts/:id/follow", MastodonAPIController, :follow)
285
286 post("/accounts/:id/unfollow", MastodonAPIController, :unfollow)
287 post("/accounts/:id/block", MastodonAPIController, :block)
288 post("/accounts/:id/unblock", MastodonAPIController, :unblock)
289 post("/accounts/:id/mute", MastodonAPIController, :mute)
290 post("/accounts/:id/unmute", MastodonAPIController, :unmute)
291
292 post("/follow_requests/:id/authorize", MastodonAPIController, :authorize_follow_request)
293 post("/follow_requests/:id/reject", MastodonAPIController, :reject_follow_request)
294
295 post("/domain_blocks", MastodonAPIController, :block_domain)
296 delete("/domain_blocks", MastodonAPIController, :unblock_domain)
297 end
298
299 scope [] do
300 pipe_through(:oauth_push)
301
302 post("/push/subscription", MastodonAPIController, :create_push_subscription)
303 get("/push/subscription", MastodonAPIController, :get_push_subscription)
304 put("/push/subscription", MastodonAPIController, :update_push_subscription)
305 delete("/push/subscription", MastodonAPIController, :delete_push_subscription)
306 end
307 end
308
309 scope "/api/web", Pleroma.Web.MastodonAPI do
310 pipe_through([:authenticated_api, :oauth_write])
311
312 put("/settings", MastodonAPIController, :put_settings)
313 end
314
315 scope "/api/v1", Pleroma.Web.MastodonAPI do
316 pipe_through(:api)
317
318 get("/instance", MastodonAPIController, :masto_instance)
319 get("/instance/peers", MastodonAPIController, :peers)
320 post("/apps", MastodonAPIController, :create_app)
321 get("/custom_emojis", MastodonAPIController, :custom_emojis)
322
323 get("/statuses/:id/card", MastodonAPIController, :status_card)
324
325 get("/statuses/:id/favourited_by", MastodonAPIController, :favourited_by)
326 get("/statuses/:id/reblogged_by", MastodonAPIController, :reblogged_by)
327
328 get("/trends", MastodonAPIController, :empty_array)
329
330 scope [] do
331 pipe_through(:oauth_read_or_unauthenticated)
332
333 get("/timelines/public", MastodonAPIController, :public_timeline)
334 get("/timelines/tag/:tag", MastodonAPIController, :hashtag_timeline)
335 get("/timelines/list/:list_id", MastodonAPIController, :list_timeline)
336
337 get("/statuses/:id", MastodonAPIController, :get_status)
338 get("/statuses/:id/context", MastodonAPIController, :get_context)
339
340 get("/accounts/:id/statuses", MastodonAPIController, :user_statuses)
341 get("/accounts/:id/followers", MastodonAPIController, :followers)
342 get("/accounts/:id/following", MastodonAPIController, :following)
343 get("/accounts/:id", MastodonAPIController, :user)
344
345 get("/search", MastodonAPIController, :search)
346 end
347 end
348
349 scope "/api/v2", Pleroma.Web.MastodonAPI do
350 pipe_through([:api, :oauth_read_or_unauthenticated])
351 get("/search", MastodonAPIController, :search2)
352 end
353
354 scope "/api", Pleroma.Web do
355 pipe_through(:config)
356
357 get("/help/test", TwitterAPI.UtilController, :help_test)
358 post("/help/test", TwitterAPI.UtilController, :help_test)
359 get("/statusnet/config", TwitterAPI.UtilController, :config)
360 get("/statusnet/version", TwitterAPI.UtilController, :version)
361 get("/pleroma/frontend_configurations", TwitterAPI.UtilController, :frontend_configurations)
362 end
363
364 scope "/api", Pleroma.Web do
365 pipe_through(:api)
366
367 post("/account/register", TwitterAPI.Controller, :register)
368 post("/account/password_reset", TwitterAPI.Controller, :password_reset)
369
370 post("/account/resend_confirmation_email", TwitterAPI.Controller, :resend_confirmation_email)
371
372 get(
373 "/account/confirm_email/:user_id/:token",
374 TwitterAPI.Controller,
375 :confirm_email,
376 as: :confirm_email
377 )
378
379 scope [] do
380 pipe_through(:oauth_read_or_unauthenticated)
381
382 get("/statuses/user_timeline", TwitterAPI.Controller, :user_timeline)
383 get("/qvitter/statuses/user_timeline", TwitterAPI.Controller, :user_timeline)
384 get("/users/show", TwitterAPI.Controller, :show_user)
385
386 get("/statuses/followers", TwitterAPI.Controller, :followers)
387 get("/statuses/friends", TwitterAPI.Controller, :friends)
388 get("/statuses/blocks", TwitterAPI.Controller, :blocks)
389 get("/statuses/show/:id", TwitterAPI.Controller, :fetch_status)
390 get("/statusnet/conversation/:id", TwitterAPI.Controller, :fetch_conversation)
391
392 get("/search", TwitterAPI.Controller, :search)
393 get("/statusnet/tags/timeline/:tag", TwitterAPI.Controller, :public_and_external_timeline)
394 end
395 end
396
397 scope "/api", Pleroma.Web do
398 pipe_through([:api, :oauth_read_or_unauthenticated])
399
400 get("/statuses/public_timeline", TwitterAPI.Controller, :public_timeline)
401
402 get(
403 "/statuses/public_and_external_timeline",
404 TwitterAPI.Controller,
405 :public_and_external_timeline
406 )
407
408 get("/statuses/networkpublic_timeline", TwitterAPI.Controller, :public_and_external_timeline)
409 end
410
411 scope "/api", Pleroma.Web, as: :twitter_api_search do
412 pipe_through([:api, :oauth_read_or_unauthenticated])
413 get("/pleroma/search_user", TwitterAPI.Controller, :search_user)
414 end
415
416 scope "/api", Pleroma.Web, as: :authenticated_twitter_api do
417 pipe_through(:authenticated_api)
418
419 get("/oauth_tokens", TwitterAPI.Controller, :oauth_tokens)
420 delete("/oauth_tokens/:id", TwitterAPI.Controller, :revoke_token)
421
422 scope [] do
423 pipe_through(:oauth_read)
424
425 get("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials)
426 post("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials)
427
428 get("/statuses/home_timeline", TwitterAPI.Controller, :friends_timeline)
429 get("/statuses/friends_timeline", TwitterAPI.Controller, :friends_timeline)
430 get("/statuses/mentions", TwitterAPI.Controller, :mentions_timeline)
431 get("/statuses/mentions_timeline", TwitterAPI.Controller, :mentions_timeline)
432 get("/statuses/dm_timeline", TwitterAPI.Controller, :dm_timeline)
433 get("/qvitter/statuses/notifications", TwitterAPI.Controller, :notifications)
434
435 get("/pleroma/friend_requests", TwitterAPI.Controller, :friend_requests)
436
437 get("/friends/ids", TwitterAPI.Controller, :friends_ids)
438 get("/friendships/no_retweets/ids", TwitterAPI.Controller, :empty_array)
439
440 get("/mutes/users/ids", TwitterAPI.Controller, :empty_array)
441 get("/qvitter/mutes", TwitterAPI.Controller, :raw_empty_array)
442
443 get("/externalprofile/show", TwitterAPI.Controller, :external_profile)
444
445 post("/qvitter/statuses/notifications/read", TwitterAPI.Controller, :notifications_read)
446 end
447
448 scope [] do
449 pipe_through(:oauth_write)
450
451 post("/account/update_profile", TwitterAPI.Controller, :update_profile)
452 post("/account/update_profile_banner", TwitterAPI.Controller, :update_banner)
453 post("/qvitter/update_background_image", TwitterAPI.Controller, :update_background)
454
455 post("/statuses/update", TwitterAPI.Controller, :status_update)
456 post("/statuses/retweet/:id", TwitterAPI.Controller, :retweet)
457 post("/statuses/unretweet/:id", TwitterAPI.Controller, :unretweet)
458 post("/statuses/destroy/:id", TwitterAPI.Controller, :delete_post)
459
460 post("/statuses/pin/:id", TwitterAPI.Controller, :pin)
461 post("/statuses/unpin/:id", TwitterAPI.Controller, :unpin)
462
463 post("/statusnet/media/upload", TwitterAPI.Controller, :upload)
464 post("/media/upload", TwitterAPI.Controller, :upload_json)
465 post("/media/metadata/create", TwitterAPI.Controller, :update_media)
466
467 post("/favorites/create/:id", TwitterAPI.Controller, :favorite)
468 post("/favorites/create", TwitterAPI.Controller, :favorite)
469 post("/favorites/destroy/:id", TwitterAPI.Controller, :unfavorite)
470
471 post("/qvitter/update_avatar", TwitterAPI.Controller, :update_avatar)
472 end
473
474 scope [] do
475 pipe_through(:oauth_follow)
476
477 post("/pleroma/friendships/approve", TwitterAPI.Controller, :approve_friend_request)
478 post("/pleroma/friendships/deny", TwitterAPI.Controller, :deny_friend_request)
479
480 post("/friendships/create", TwitterAPI.Controller, :follow)
481 post("/friendships/destroy", TwitterAPI.Controller, :unfollow)
482
483 post("/blocks/create", TwitterAPI.Controller, :block)
484 post("/blocks/destroy", TwitterAPI.Controller, :unblock)
485 end
486 end
487
488 pipeline :ap_relay do
489 plug(:accepts, ["activity+json"])
490 end
491
492 pipeline :ostatus do
493 plug(:accepts, ["html", "xml", "atom", "activity+json"])
494 end
495
496 pipeline :oembed do
497 plug(:accepts, ["json", "xml"])
498 end
499
500 scope "/", Pleroma.Web do
501 pipe_through(:ostatus)
502
503 get("/objects/:uuid", OStatus.OStatusController, :object)
504 get("/activities/:uuid", OStatus.OStatusController, :activity)
505 get("/notice/:id", OStatus.OStatusController, :notice)
506 get("/users/:nickname/feed", OStatus.OStatusController, :feed)
507 get("/users/:nickname", OStatus.OStatusController, :feed_redirect)
508
509 post("/users/:nickname/salmon", OStatus.OStatusController, :salmon_incoming)
510 post("/push/hub/:nickname", Websub.WebsubController, :websub_subscription_request)
511 get("/push/subscriptions/:id", Websub.WebsubController, :websub_subscription_confirmation)
512 post("/push/subscriptions/:id", Websub.WebsubController, :websub_incoming)
513 end
514
515 scope "/", Pleroma.Web do
516 pipe_through(:oembed)
517
518 get("/oembed", OEmbed.OEmbedController, :url)
519 end
520
521 pipeline :activitypub do
522 plug(:accepts, ["activity+json"])
523 plug(Pleroma.Web.Plugs.HTTPSignaturePlug)
524 end
525
526 scope "/", Pleroma.Web.ActivityPub do
527 # XXX: not really ostatus
528 pipe_through(:ostatus)
529
530 get("/users/:nickname/followers", ActivityPubController, :followers)
531 get("/users/:nickname/following", ActivityPubController, :following)
532 get("/users/:nickname/outbox", ActivityPubController, :outbox)
533 get("/objects/:uuid/likes", ActivityPubController, :object_likes)
534 end
535
536 pipeline :activitypub_client do
537 plug(:accepts, ["activity+json"])
538 plug(:fetch_session)
539 plug(Pleroma.Plugs.OAuthPlug)
540 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
541 plug(Pleroma.Plugs.UserFetcherPlug)
542 plug(Pleroma.Plugs.SessionAuthenticationPlug)
543 plug(Pleroma.Plugs.LegacyAuthenticationPlug)
544 plug(Pleroma.Plugs.AuthenticationPlug)
545 plug(Pleroma.Plugs.UserEnabledPlug)
546 plug(Pleroma.Plugs.SetUserSessionIdPlug)
547 plug(Pleroma.Plugs.EnsureUserKeyPlug)
548 end
549
550 scope "/", Pleroma.Web.ActivityPub do
551 pipe_through([:activitypub_client])
552
553 scope [] do
554 pipe_through(:oauth_read)
555 get("/api/ap/whoami", ActivityPubController, :whoami)
556 get("/users/:nickname/inbox", ActivityPubController, :read_inbox)
557 end
558
559 scope [] do
560 pipe_through(:oauth_write)
561 post("/users/:nickname/outbox", ActivityPubController, :update_outbox)
562 end
563 end
564
565 scope "/relay", Pleroma.Web.ActivityPub do
566 pipe_through(:ap_relay)
567 get("/", ActivityPubController, :relay)
568 end
569
570 scope "/", Pleroma.Web.ActivityPub do
571 pipe_through(:activitypub)
572 post("/inbox", ActivityPubController, :inbox)
573 post("/users/:nickname/inbox", ActivityPubController, :inbox)
574 end
575
576 scope "/.well-known", Pleroma.Web do
577 pipe_through(:well_known)
578
579 get("/host-meta", WebFinger.WebFingerController, :host_meta)
580 get("/webfinger", WebFinger.WebFingerController, :webfinger)
581 get("/nodeinfo", Nodeinfo.NodeinfoController, :schemas)
582 end
583
584 scope "/nodeinfo", Pleroma.Web do
585 get("/:version", Nodeinfo.NodeinfoController, :nodeinfo)
586 end
587
588 scope "/", Pleroma.Web.MastodonAPI do
589 pipe_through(:mastodon_html)
590
591 get("/web/login", MastodonAPIController, :login)
592 delete("/auth/sign_out", MastodonAPIController, :logout)
593
594 scope [] do
595 pipe_through(:oauth_read_or_unauthenticated)
596 get("/web/*path", MastodonAPIController, :index)
597 end
598 end
599
600 pipeline :remote_media do
601 end
602
603 scope "/proxy/", Pleroma.Web.MediaProxy do
604 pipe_through(:remote_media)
605
606 get("/:sig/:url", MediaProxyController, :remote)
607 get("/:sig/:url/:filename", MediaProxyController, :remote)
608 end
609
610 if Mix.env() == :dev do
611 scope "/dev" do
612 pipe_through([:mailbox_preview])
613
614 forward("/mailbox", Plug.Swoosh.MailboxPreview, base_path: "/dev/mailbox")
615 end
616 end
617
618 scope "/", Fallback do
619 get("/registration/:token", RedirectController, :registration_page)
620 get("/:maybe_nickname_or_id", RedirectController, :redirector_with_meta)
621 get("/*path", RedirectController, :redirector)
622
623 options("/*path", RedirectController, :empty)
624 end
625 end
626
627 defmodule Fallback.RedirectController do
628 use Pleroma.Web, :controller
629 alias Pleroma.Web.Metadata
630 alias Pleroma.User
631
632 def redirector(conn, _params, code \\ 200) do
633 conn
634 |> put_resp_content_type("text/html")
635 |> send_file(code, index_file_path())
636 end
637
638 def redirector_with_meta(conn, %{"maybe_nickname_or_id" => maybe_nickname_or_id} = params) do
639 with %User{} = user <- User.get_cached_by_nickname_or_id(maybe_nickname_or_id) do
640 redirector_with_meta(conn, %{user: user})
641 else
642 nil ->
643 redirector(conn, params)
644 end
645 end
646
647 def redirector_with_meta(conn, params) do
648 {:ok, index_content} = File.read(index_file_path())
649 tags = Metadata.build_tags(params)
650 response = String.replace(index_content, "<!--server-generated-meta-->", tags)
651
652 conn
653 |> put_resp_content_type("text/html")
654 |> send_resp(200, response)
655 end
656
657 def index_file_path do
658 Pleroma.Plugs.InstanceStatic.file_path("index.html")
659 end
660
661 def registration_page(conn, params) do
662 redirector(conn, params)
663 end
664
665 def empty(conn, _params) do
666 conn
667 |> put_status(204)
668 |> text("")
669 end
670 end