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