[#468] Merged `upstream/develop`, resolved conflicts.
[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 end
234
235 scope [] do
236 pipe_through(:oauth_write)
237
238 patch("/accounts/update_credentials", MastodonAPIController, :update_credentials)
239
240 post("/statuses", MastodonAPIController, :post_status)
241 delete("/statuses/:id", MastodonAPIController, :delete_status)
242
243 post("/statuses/:id/reblog", MastodonAPIController, :reblog_status)
244 post("/statuses/:id/unreblog", MastodonAPIController, :unreblog_status)
245 post("/statuses/:id/favourite", MastodonAPIController, :fav_status)
246 post("/statuses/:id/unfavourite", MastodonAPIController, :unfav_status)
247 post("/statuses/:id/pin", MastodonAPIController, :pin_status)
248 post("/statuses/:id/unpin", MastodonAPIController, :unpin_status)
249 post("/statuses/:id/bookmark", MastodonAPIController, :bookmark_status)
250 post("/statuses/:id/unbookmark", MastodonAPIController, :unbookmark_status)
251 post("/statuses/:id/mute", MastodonAPIController, :mute_conversation)
252 post("/statuses/:id/unmute", MastodonAPIController, :unmute_conversation)
253
254 post("/media", MastodonAPIController, :upload)
255 put("/media/:id", MastodonAPIController, :update_media)
256
257 delete("/lists/:id", MastodonAPIController, :delete_list)
258 post("/lists", MastodonAPIController, :create_list)
259 put("/lists/:id", MastodonAPIController, :rename_list)
260
261 post("/lists/:id/accounts", MastodonAPIController, :add_to_list)
262 delete("/lists/:id/accounts", MastodonAPIController, :remove_from_list)
263
264 post("/filters", MastodonAPIController, :create_filter)
265 get("/filters/:id", MastodonAPIController, :get_filter)
266 put("/filters/:id", MastodonAPIController, :update_filter)
267 delete("/filters/:id", MastodonAPIController, :delete_filter)
268 end
269
270 scope [] do
271 pipe_through(:oauth_follow)
272
273 post("/follows", MastodonAPIController, :follow)
274 post("/accounts/:id/follow", MastodonAPIController, :follow)
275
276 post("/accounts/:id/unfollow", MastodonAPIController, :unfollow)
277 post("/accounts/:id/block", MastodonAPIController, :block)
278 post("/accounts/:id/unblock", MastodonAPIController, :unblock)
279 post("/accounts/:id/mute", MastodonAPIController, :relationship_noop)
280 post("/accounts/:id/unmute", MastodonAPIController, :relationship_noop)
281
282 post("/follow_requests/:id/authorize", MastodonAPIController, :authorize_follow_request)
283 post("/follow_requests/:id/reject", MastodonAPIController, :reject_follow_request)
284
285 post("/domain_blocks", MastodonAPIController, :block_domain)
286 delete("/domain_blocks", MastodonAPIController, :unblock_domain)
287
288 post("/push/subscription", MastodonAPIController, :create_push_subscription)
289 get("/push/subscription", MastodonAPIController, :get_push_subscription)
290 put("/push/subscription", MastodonAPIController, :update_push_subscription)
291 delete("/push/subscription", MastodonAPIController, :delete_push_subscription)
292 end
293 end
294
295 scope "/api/web", Pleroma.Web.MastodonAPI do
296 pipe_through([:authenticated_api, :oauth_write])
297
298 put("/settings", MastodonAPIController, :put_settings)
299 end
300
301 scope "/api/v1", Pleroma.Web.MastodonAPI do
302 pipe_through(:api)
303
304 get("/instance", MastodonAPIController, :masto_instance)
305 get("/instance/peers", MastodonAPIController, :peers)
306 post("/apps", MastodonAPIController, :create_app)
307 get("/custom_emojis", MastodonAPIController, :custom_emojis)
308
309 get("/statuses/:id/card", MastodonAPIController, :status_card)
310
311 get("/statuses/:id/favourited_by", MastodonAPIController, :favourited_by)
312 get("/statuses/:id/reblogged_by", MastodonAPIController, :reblogged_by)
313
314 get("/trends", MastodonAPIController, :empty_array)
315
316 scope [] do
317 pipe_through(:oauth_read_or_unauthenticated)
318
319 get("/timelines/public", MastodonAPIController, :public_timeline)
320 get("/timelines/tag/:tag", MastodonAPIController, :hashtag_timeline)
321 get("/timelines/list/:list_id", MastodonAPIController, :list_timeline)
322
323 get("/statuses/:id", MastodonAPIController, :get_status)
324 get("/statuses/:id/context", MastodonAPIController, :get_context)
325
326 get("/accounts/:id/statuses", MastodonAPIController, :user_statuses)
327 get("/accounts/:id/followers", MastodonAPIController, :followers)
328 get("/accounts/:id/following", MastodonAPIController, :following)
329 get("/accounts/:id", MastodonAPIController, :user)
330
331 get("/search", MastodonAPIController, :search)
332 end
333 end
334
335 scope "/api/v2", Pleroma.Web.MastodonAPI do
336 pipe_through([:api, :oauth_read_or_unauthenticated])
337 get("/search", MastodonAPIController, :search2)
338 end
339
340 scope "/api", Pleroma.Web do
341 pipe_through(:config)
342
343 get("/help/test", TwitterAPI.UtilController, :help_test)
344 post("/help/test", TwitterAPI.UtilController, :help_test)
345 get("/statusnet/config", TwitterAPI.UtilController, :config)
346 get("/statusnet/version", TwitterAPI.UtilController, :version)
347 get("/pleroma/frontend_configurations", TwitterAPI.UtilController, :frontend_configurations)
348 end
349
350 scope "/api", Pleroma.Web do
351 pipe_through(:api)
352
353 post("/account/register", TwitterAPI.Controller, :register)
354 post("/account/password_reset", TwitterAPI.Controller, :password_reset)
355
356 post("/account/resend_confirmation_email", TwitterAPI.Controller, :resend_confirmation_email)
357
358 get(
359 "/account/confirm_email/:user_id/:token",
360 TwitterAPI.Controller,
361 :confirm_email,
362 as: :confirm_email
363 )
364
365 scope [] do
366 pipe_through(:oauth_read_or_unauthenticated)
367
368 get("/statuses/user_timeline", TwitterAPI.Controller, :user_timeline)
369 get("/qvitter/statuses/user_timeline", TwitterAPI.Controller, :user_timeline)
370 get("/users/show", TwitterAPI.Controller, :show_user)
371
372 get("/statuses/followers", TwitterAPI.Controller, :followers)
373 get("/statuses/friends", TwitterAPI.Controller, :friends)
374 get("/statuses/blocks", TwitterAPI.Controller, :blocks)
375 get("/statuses/show/:id", TwitterAPI.Controller, :fetch_status)
376 get("/statusnet/conversation/:id", TwitterAPI.Controller, :fetch_conversation)
377
378 get("/search", TwitterAPI.Controller, :search)
379 get("/statusnet/tags/timeline/:tag", TwitterAPI.Controller, :public_and_external_timeline)
380 end
381 end
382
383 scope "/api", Pleroma.Web do
384 pipe_through([:api, :oauth_read_or_unauthenticated])
385
386 get("/statuses/public_timeline", TwitterAPI.Controller, :public_timeline)
387
388 get(
389 "/statuses/public_and_external_timeline",
390 TwitterAPI.Controller,
391 :public_and_external_timeline
392 )
393
394 get("/statuses/networkpublic_timeline", TwitterAPI.Controller, :public_and_external_timeline)
395 end
396
397 scope "/api", Pleroma.Web, as: :twitter_api_search do
398 pipe_through([:api, :oauth_read_or_unauthenticated])
399 get("/pleroma/search_user", TwitterAPI.Controller, :search_user)
400 end
401
402 scope "/api", Pleroma.Web, as: :authenticated_twitter_api do
403 pipe_through(:authenticated_api)
404
405 scope [] do
406 pipe_through(:oauth_read)
407
408 get("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials)
409 post("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials)
410
411 get("/statuses/home_timeline", TwitterAPI.Controller, :friends_timeline)
412 get("/statuses/friends_timeline", TwitterAPI.Controller, :friends_timeline)
413 get("/statuses/mentions", TwitterAPI.Controller, :mentions_timeline)
414 get("/statuses/mentions_timeline", TwitterAPI.Controller, :mentions_timeline)
415 get("/statuses/dm_timeline", TwitterAPI.Controller, :dm_timeline)
416 get("/qvitter/statuses/notifications", TwitterAPI.Controller, :notifications)
417
418 get("/pleroma/friend_requests", TwitterAPI.Controller, :friend_requests)
419
420 get("/friends/ids", TwitterAPI.Controller, :friends_ids)
421 get("/friendships/no_retweets/ids", TwitterAPI.Controller, :empty_array)
422
423 get("/mutes/users/ids", TwitterAPI.Controller, :empty_array)
424 get("/qvitter/mutes", TwitterAPI.Controller, :raw_empty_array)
425
426 get("/externalprofile/show", TwitterAPI.Controller, :external_profile)
427
428 post("/qvitter/statuses/notifications/read", TwitterAPI.Controller, :notifications_read)
429 end
430
431 scope [] do
432 pipe_through(:oauth_write)
433
434 post("/account/update_profile", TwitterAPI.Controller, :update_profile)
435 post("/account/update_profile_banner", TwitterAPI.Controller, :update_banner)
436 post("/qvitter/update_background_image", TwitterAPI.Controller, :update_background)
437
438 post("/statuses/update", TwitterAPI.Controller, :status_update)
439 post("/statuses/retweet/:id", TwitterAPI.Controller, :retweet)
440 post("/statuses/unretweet/:id", TwitterAPI.Controller, :unretweet)
441 post("/statuses/destroy/:id", TwitterAPI.Controller, :delete_post)
442
443 post("/statuses/pin/:id", TwitterAPI.Controller, :pin)
444 post("/statuses/unpin/:id", TwitterAPI.Controller, :unpin)
445
446 post("/statusnet/media/upload", TwitterAPI.Controller, :upload)
447 post("/media/upload", TwitterAPI.Controller, :upload_json)
448 post("/media/metadata/create", TwitterAPI.Controller, :update_media)
449
450 post("/favorites/create/:id", TwitterAPI.Controller, :favorite)
451 post("/favorites/create", TwitterAPI.Controller, :favorite)
452 post("/favorites/destroy/:id", TwitterAPI.Controller, :unfavorite)
453
454 post("/qvitter/update_avatar", TwitterAPI.Controller, :update_avatar)
455 end
456
457 scope [] do
458 pipe_through(:oauth_follow)
459
460 post("/pleroma/friendships/approve", TwitterAPI.Controller, :approve_friend_request)
461 post("/pleroma/friendships/deny", TwitterAPI.Controller, :deny_friend_request)
462
463 post("/friendships/create", TwitterAPI.Controller, :follow)
464 post("/friendships/destroy", TwitterAPI.Controller, :unfollow)
465
466 post("/blocks/create", TwitterAPI.Controller, :block)
467 post("/blocks/destroy", TwitterAPI.Controller, :unblock)
468 end
469 end
470
471 pipeline :ap_relay do
472 plug(:accepts, ["activity+json"])
473 end
474
475 pipeline :ostatus do
476 plug(:accepts, ["html", "xml", "atom", "activity+json"])
477 end
478
479 pipeline :oembed do
480 plug(:accepts, ["json", "xml"])
481 end
482
483 scope "/", Pleroma.Web do
484 pipe_through(:ostatus)
485
486 get("/objects/:uuid", OStatus.OStatusController, :object)
487 get("/activities/:uuid", OStatus.OStatusController, :activity)
488 get("/notice/:id", OStatus.OStatusController, :notice)
489 get("/users/:nickname/feed", OStatus.OStatusController, :feed)
490 get("/users/:nickname", OStatus.OStatusController, :feed_redirect)
491
492 post("/users/:nickname/salmon", OStatus.OStatusController, :salmon_incoming)
493 post("/push/hub/:nickname", Websub.WebsubController, :websub_subscription_request)
494 get("/push/subscriptions/:id", Websub.WebsubController, :websub_subscription_confirmation)
495 post("/push/subscriptions/:id", Websub.WebsubController, :websub_incoming)
496 end
497
498 scope "/", Pleroma.Web do
499 pipe_through(:oembed)
500
501 get("/oembed", OEmbed.OEmbedController, :url)
502 end
503
504 pipeline :activitypub do
505 plug(:accepts, ["activity+json"])
506 plug(Pleroma.Web.Plugs.HTTPSignaturePlug)
507 end
508
509 scope "/", Pleroma.Web.ActivityPub do
510 # XXX: not really ostatus
511 pipe_through(:ostatus)
512
513 get("/users/:nickname/followers", ActivityPubController, :followers)
514 get("/users/:nickname/following", ActivityPubController, :following)
515 get("/users/:nickname/outbox", ActivityPubController, :outbox)
516 get("/objects/:uuid/likes", ActivityPubController, :object_likes)
517 end
518
519 pipeline :activitypub_client do
520 plug(:accepts, ["activity+json"])
521 plug(:fetch_session)
522 plug(Pleroma.Plugs.OAuthPlug)
523 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
524 plug(Pleroma.Plugs.UserFetcherPlug)
525 plug(Pleroma.Plugs.SessionAuthenticationPlug)
526 plug(Pleroma.Plugs.LegacyAuthenticationPlug)
527 plug(Pleroma.Plugs.AuthenticationPlug)
528 plug(Pleroma.Plugs.UserEnabledPlug)
529 plug(Pleroma.Plugs.SetUserSessionIdPlug)
530 plug(Pleroma.Plugs.EnsureUserKeyPlug)
531 end
532
533 scope "/", Pleroma.Web.ActivityPub do
534 pipe_through([:activitypub_client])
535
536 scope [] do
537 pipe_through(:oauth_read)
538 get("/api/ap/whoami", ActivityPubController, :whoami)
539 get("/users/:nickname/inbox", ActivityPubController, :read_inbox)
540 end
541
542 scope [] do
543 pipe_through(:oauth_write)
544 post("/users/:nickname/outbox", ActivityPubController, :update_outbox)
545 end
546 end
547
548 scope "/relay", Pleroma.Web.ActivityPub do
549 pipe_through(:ap_relay)
550 get("/", ActivityPubController, :relay)
551 end
552
553 scope "/", Pleroma.Web.ActivityPub do
554 pipe_through(:activitypub)
555 post("/inbox", ActivityPubController, :inbox)
556 post("/users/:nickname/inbox", ActivityPubController, :inbox)
557 end
558
559 scope "/.well-known", Pleroma.Web do
560 pipe_through(:well_known)
561
562 get("/host-meta", WebFinger.WebFingerController, :host_meta)
563 get("/webfinger", WebFinger.WebFingerController, :webfinger)
564 get("/nodeinfo", Nodeinfo.NodeinfoController, :schemas)
565 end
566
567 scope "/nodeinfo", Pleroma.Web do
568 get("/:version", Nodeinfo.NodeinfoController, :nodeinfo)
569 end
570
571 scope "/", Pleroma.Web.MastodonAPI do
572 pipe_through(:mastodon_html)
573
574 get("/web/login", MastodonAPIController, :login)
575 delete("/auth/sign_out", MastodonAPIController, :logout)
576
577 scope [] do
578 pipe_through(:oauth_read)
579 get("/web/*path", MastodonAPIController, :index)
580 end
581 end
582
583 pipeline :remote_media do
584 end
585
586 scope "/proxy/", Pleroma.Web.MediaProxy do
587 pipe_through(:remote_media)
588
589 get("/:sig/:url", MediaProxyController, :remote)
590 get("/:sig/:url/:filename", MediaProxyController, :remote)
591 end
592
593 if Mix.env() == :dev do
594 scope "/dev" do
595 pipe_through([:mailbox_preview])
596
597 forward("/mailbox", Plug.Swoosh.MailboxPreview, base_path: "/dev/mailbox")
598 end
599 end
600
601 scope "/", Fallback do
602 get("/registration/:token", RedirectController, :registration_page)
603 get("/:maybe_nickname_or_id", RedirectController, :redirector_with_meta)
604 get("/*path", RedirectController, :redirector)
605
606 options("/*path", RedirectController, :empty)
607 end
608 end
609
610 defmodule Fallback.RedirectController do
611 use Pleroma.Web, :controller
612 alias Pleroma.Web.Metadata
613 alias Pleroma.User
614
615 def redirector(conn, _params, code \\ 200) do
616 conn
617 |> put_resp_content_type("text/html")
618 |> send_file(code, index_file_path())
619 end
620
621 def redirector_with_meta(conn, %{"maybe_nickname_or_id" => maybe_nickname_or_id} = params) do
622 with %User{} = user <- User.get_cached_by_nickname_or_id(maybe_nickname_or_id) do
623 redirector_with_meta(conn, %{user: user})
624 else
625 nil ->
626 redirector(conn, params)
627 end
628 end
629
630 def redirector_with_meta(conn, params) do
631 {:ok, index_content} = File.read(index_file_path())
632 tags = Metadata.build_tags(params)
633 response = String.replace(index_content, "<!--server-generated-meta-->", tags)
634
635 conn
636 |> put_resp_content_type("text/html")
637 |> send_resp(200, response)
638 end
639
640 def index_file_path do
641 Pleroma.Plugs.InstanceStatic.file_path("index.html")
642 end
643
644 def registration_page(conn, params) do
645 redirector(conn, params)
646 end
647
648 def empty(conn, _params) do
649 conn
650 |> put_status(204)
651 |> text("")
652 end
653 end