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