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