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