adding destroy multiple for mastofe
[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 end
139
140 scope "/api/pleroma", Pleroma.Web do
141 pipe_through(:pleroma_api)
142 post("/uploader_callback/:upload_path", UploaderController, :callback)
143 end
144
145 scope "/api/pleroma/admin", Pleroma.Web.AdminAPI do
146 pipe_through([:admin_api, :oauth_write])
147
148 post("/user/follow", AdminAPIController, :user_follow)
149 post("/user/unfollow", AdminAPIController, :user_unfollow)
150
151 get("/users", AdminAPIController, :list_users)
152 get("/users/:nickname", AdminAPIController, :user_show)
153
154 delete("/user", AdminAPIController, :user_delete)
155 patch("/users/:nickname/toggle_activation", AdminAPIController, :user_toggle_activation)
156 post("/user", AdminAPIController, :user_create)
157 put("/users/tag", AdminAPIController, :tag_users)
158 delete("/users/tag", AdminAPIController, :untag_users)
159
160 get("/permission_group/:nickname", AdminAPIController, :right_get)
161 get("/permission_group/:nickname/:permission_group", AdminAPIController, :right_get)
162 post("/permission_group/:nickname/:permission_group", AdminAPIController, :right_add)
163 delete("/permission_group/:nickname/:permission_group", AdminAPIController, :right_delete)
164
165 put("/activation_status/:nickname", AdminAPIController, :set_activation_status)
166
167 post("/relay", AdminAPIController, :relay_follow)
168 delete("/relay", AdminAPIController, :relay_unfollow)
169
170 get("/invite_token", AdminAPIController, :get_invite_token)
171 get("/invites", AdminAPIController, :invites)
172 post("/revoke_invite", AdminAPIController, :revoke_invite)
173 post("/email_invite", AdminAPIController, :email_invite)
174
175 get("/password_reset", AdminAPIController, :get_password_reset)
176 end
177
178 scope "/", Pleroma.Web.TwitterAPI do
179 pipe_through(:pleroma_html)
180
181 post("/main/ostatus", UtilController, :remote_subscribe)
182 get("/ostatus_subscribe", UtilController, :remote_follow)
183
184 scope [] do
185 pipe_through(:oauth_follow)
186 post("/ostatus_subscribe", UtilController, :do_remote_follow)
187 end
188 end
189
190 scope "/api/pleroma", Pleroma.Web.TwitterAPI do
191 pipe_through(:authenticated_api)
192
193 scope [] do
194 pipe_through(:oauth_write)
195
196 post("/change_password", UtilController, :change_password)
197 post("/delete_account", UtilController, :delete_account)
198 put("/notification_settings", UtilController, :update_notificaton_settings)
199 end
200
201 scope [] do
202 pipe_through(:oauth_follow)
203
204 post("/blocks_import", UtilController, :blocks_import)
205 post("/follow_import", UtilController, :follow_import)
206 end
207
208 scope [] do
209 pipe_through(:oauth_read)
210
211 post("/notifications/read", UtilController, :notifications_read)
212 end
213 end
214
215 scope "/oauth", Pleroma.Web.OAuth do
216 scope [] do
217 pipe_through(:oauth)
218 get("/authorize", OAuthController, :authorize)
219 end
220
221 post("/authorize", OAuthController, :create_authorization)
222 post("/token", OAuthController, :token_exchange)
223 post("/revoke", OAuthController, :token_revoke)
224 get("/registration_details", OAuthController, :registration_details)
225
226 scope [] do
227 pipe_through(:browser)
228
229 get("/prepare_request", OAuthController, :prepare_request)
230 get("/:provider", OAuthController, :request)
231 get("/:provider/callback", OAuthController, :callback)
232 post("/register", OAuthController, :register)
233 end
234 end
235
236 scope "/api/v1", Pleroma.Web.MastodonAPI do
237 pipe_through(:authenticated_api)
238
239 scope [] do
240 pipe_through(:oauth_read)
241
242 get("/accounts/verify_credentials", MastodonAPIController, :verify_credentials)
243
244 get("/accounts/relationships", MastodonAPIController, :relationships)
245 get("/accounts/search", MastodonAPIController, :account_search)
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 scope [] do
381 pipe_through(:oauth_read_or_unauthenticated)
382
383 get("/timelines/public", MastodonAPIController, :public_timeline)
384 get("/timelines/tag/:tag", MastodonAPIController, :hashtag_timeline)
385 get("/timelines/list/:list_id", MastodonAPIController, :list_timeline)
386
387 get("/statuses/:id", MastodonAPIController, :get_status)
388 get("/statuses/:id/context", MastodonAPIController, :get_context)
389
390 get("/accounts/:id/statuses", MastodonAPIController, :user_statuses)
391 get("/accounts/:id/followers", MastodonAPIController, :followers)
392 get("/accounts/:id/following", MastodonAPIController, :following)
393 get("/accounts/:id", MastodonAPIController, :user)
394
395 get("/search", MastodonAPIController, :search)
396 end
397 end
398
399 scope "/api/v2", Pleroma.Web.MastodonAPI do
400 pipe_through([:api, :oauth_read_or_unauthenticated])
401 get("/search", MastodonAPIController, :search2)
402 end
403
404 scope "/api", Pleroma.Web do
405 pipe_through(:config)
406
407 get("/help/test", TwitterAPI.UtilController, :help_test)
408 post("/help/test", TwitterAPI.UtilController, :help_test)
409 get("/statusnet/config", TwitterAPI.UtilController, :config)
410 get("/statusnet/version", TwitterAPI.UtilController, :version)
411 get("/pleroma/frontend_configurations", TwitterAPI.UtilController, :frontend_configurations)
412 end
413
414 scope "/api", Pleroma.Web do
415 pipe_through(:api)
416
417 post("/account/register", TwitterAPI.Controller, :register)
418 post("/account/password_reset", TwitterAPI.Controller, :password_reset)
419
420 post("/account/resend_confirmation_email", TwitterAPI.Controller, :resend_confirmation_email)
421
422 get(
423 "/account/confirm_email/:user_id/:token",
424 TwitterAPI.Controller,
425 :confirm_email,
426 as: :confirm_email
427 )
428
429 scope [] do
430 pipe_through(:oauth_read_or_unauthenticated)
431
432 get("/statuses/user_timeline", TwitterAPI.Controller, :user_timeline)
433 get("/qvitter/statuses/user_timeline", TwitterAPI.Controller, :user_timeline)
434 get("/users/show", TwitterAPI.Controller, :show_user)
435
436 get("/statuses/followers", TwitterAPI.Controller, :followers)
437 get("/statuses/friends", TwitterAPI.Controller, :friends)
438 get("/statuses/blocks", TwitterAPI.Controller, :blocks)
439 get("/statuses/show/:id", TwitterAPI.Controller, :fetch_status)
440 get("/statusnet/conversation/:id", TwitterAPI.Controller, :fetch_conversation)
441
442 get("/search", TwitterAPI.Controller, :search)
443 get("/statusnet/tags/timeline/:tag", TwitterAPI.Controller, :public_and_external_timeline)
444 end
445 end
446
447 scope "/api", Pleroma.Web do
448 pipe_through([:api, :oauth_read_or_unauthenticated])
449
450 get("/statuses/public_timeline", TwitterAPI.Controller, :public_timeline)
451
452 get(
453 "/statuses/public_and_external_timeline",
454 TwitterAPI.Controller,
455 :public_and_external_timeline
456 )
457
458 get("/statuses/networkpublic_timeline", TwitterAPI.Controller, :public_and_external_timeline)
459 end
460
461 scope "/api", Pleroma.Web, as: :twitter_api_search do
462 pipe_through([:api, :oauth_read_or_unauthenticated])
463 get("/pleroma/search_user", TwitterAPI.Controller, :search_user)
464 end
465
466 scope "/api", Pleroma.Web, as: :authenticated_twitter_api do
467 pipe_through(:authenticated_api)
468
469 get("/oauth_tokens", TwitterAPI.Controller, :oauth_tokens)
470 delete("/oauth_tokens/:id", TwitterAPI.Controller, :revoke_token)
471
472 scope [] do
473 pipe_through(:oauth_read)
474
475 get("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials)
476 post("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials)
477
478 get("/statuses/home_timeline", TwitterAPI.Controller, :friends_timeline)
479 get("/statuses/friends_timeline", TwitterAPI.Controller, :friends_timeline)
480 get("/statuses/mentions", TwitterAPI.Controller, :mentions_timeline)
481 get("/statuses/mentions_timeline", TwitterAPI.Controller, :mentions_timeline)
482 get("/statuses/dm_timeline", TwitterAPI.Controller, :dm_timeline)
483 get("/qvitter/statuses/notifications", TwitterAPI.Controller, :notifications)
484
485 get("/pleroma/friend_requests", TwitterAPI.Controller, :friend_requests)
486
487 get("/friends/ids", TwitterAPI.Controller, :friends_ids)
488 get("/friendships/no_retweets/ids", TwitterAPI.Controller, :empty_array)
489
490 get("/mutes/users/ids", TwitterAPI.Controller, :empty_array)
491 get("/qvitter/mutes", TwitterAPI.Controller, :raw_empty_array)
492
493 get("/externalprofile/show", TwitterAPI.Controller, :external_profile)
494
495 post("/qvitter/statuses/notifications/read", TwitterAPI.Controller, :notifications_read)
496 end
497
498 scope [] do
499 pipe_through(:oauth_write)
500
501 post("/account/update_profile", TwitterAPI.Controller, :update_profile)
502 post("/account/update_profile_banner", TwitterAPI.Controller, :update_banner)
503 post("/qvitter/update_background_image", TwitterAPI.Controller, :update_background)
504
505 post("/statuses/update", TwitterAPI.Controller, :status_update)
506 post("/statuses/retweet/:id", TwitterAPI.Controller, :retweet)
507 post("/statuses/unretweet/:id", TwitterAPI.Controller, :unretweet)
508 post("/statuses/destroy/:id", TwitterAPI.Controller, :delete_post)
509
510 post("/statuses/pin/:id", TwitterAPI.Controller, :pin)
511 post("/statuses/unpin/:id", TwitterAPI.Controller, :unpin)
512
513 post("/statusnet/media/upload", TwitterAPI.Controller, :upload)
514 post("/media/upload", TwitterAPI.Controller, :upload_json)
515 post("/media/metadata/create", TwitterAPI.Controller, :update_media)
516
517 post("/favorites/create/:id", TwitterAPI.Controller, :favorite)
518 post("/favorites/create", TwitterAPI.Controller, :favorite)
519 post("/favorites/destroy/:id", TwitterAPI.Controller, :unfavorite)
520
521 post("/qvitter/update_avatar", TwitterAPI.Controller, :update_avatar)
522 end
523
524 scope [] do
525 pipe_through(:oauth_follow)
526
527 post("/pleroma/friendships/approve", TwitterAPI.Controller, :approve_friend_request)
528 post("/pleroma/friendships/deny", TwitterAPI.Controller, :deny_friend_request)
529
530 post("/friendships/create", TwitterAPI.Controller, :follow)
531 post("/friendships/destroy", TwitterAPI.Controller, :unfollow)
532
533 post("/blocks/create", TwitterAPI.Controller, :block)
534 post("/blocks/destroy", TwitterAPI.Controller, :unblock)
535 end
536 end
537
538 pipeline :ap_relay do
539 plug(:accepts, ["activity+json", "json"])
540 end
541
542 pipeline :ostatus do
543 plug(:accepts, ["html", "xml", "atom", "activity+json", "json"])
544 end
545
546 pipeline :oembed do
547 plug(:accepts, ["json", "xml"])
548 end
549
550 scope "/", Pleroma.Web do
551 pipe_through(:ostatus)
552
553 get("/objects/:uuid", OStatus.OStatusController, :object)
554 get("/activities/:uuid", OStatus.OStatusController, :activity)
555 get("/notice/:id", OStatus.OStatusController, :notice)
556 get("/notice/:id/embed_player", OStatus.OStatusController, :notice_player)
557 get("/users/:nickname/feed", OStatus.OStatusController, :feed)
558 get("/users/:nickname", OStatus.OStatusController, :feed_redirect)
559
560 post("/users/:nickname/salmon", OStatus.OStatusController, :salmon_incoming)
561 post("/push/hub/:nickname", Websub.WebsubController, :websub_subscription_request)
562 get("/push/subscriptions/:id", Websub.WebsubController, :websub_subscription_confirmation)
563 post("/push/subscriptions/:id", Websub.WebsubController, :websub_incoming)
564 end
565
566 scope "/", Pleroma.Web do
567 pipe_through(:oembed)
568
569 get("/oembed", OEmbed.OEmbedController, :url)
570 end
571
572 pipeline :activitypub do
573 plug(:accepts, ["activity+json", "json"])
574 plug(Pleroma.Web.Plugs.HTTPSignaturePlug)
575 end
576
577 scope "/", Pleroma.Web.ActivityPub do
578 # XXX: not really ostatus
579 pipe_through(:ostatus)
580
581 get("/users/:nickname/followers", ActivityPubController, :followers)
582 get("/users/:nickname/following", ActivityPubController, :following)
583 get("/users/:nickname/outbox", ActivityPubController, :outbox)
584 get("/objects/:uuid/likes", ActivityPubController, :object_likes)
585 end
586
587 pipeline :activitypub_client do
588 plug(:accepts, ["activity+json", "json"])
589 plug(:fetch_session)
590 plug(Pleroma.Plugs.OAuthPlug)
591 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
592 plug(Pleroma.Plugs.UserFetcherPlug)
593 plug(Pleroma.Plugs.SessionAuthenticationPlug)
594 plug(Pleroma.Plugs.LegacyAuthenticationPlug)
595 plug(Pleroma.Plugs.AuthenticationPlug)
596 plug(Pleroma.Plugs.UserEnabledPlug)
597 plug(Pleroma.Plugs.SetUserSessionIdPlug)
598 plug(Pleroma.Plugs.EnsureUserKeyPlug)
599 end
600
601 scope "/", Pleroma.Web.ActivityPub do
602 pipe_through([:activitypub_client])
603
604 scope [] do
605 pipe_through(:oauth_read)
606 get("/api/ap/whoami", ActivityPubController, :whoami)
607 get("/users/:nickname/inbox", ActivityPubController, :read_inbox)
608 end
609
610 scope [] do
611 pipe_through(:oauth_write)
612 post("/users/:nickname/outbox", ActivityPubController, :update_outbox)
613 end
614 end
615
616 scope "/relay", Pleroma.Web.ActivityPub do
617 pipe_through(:ap_relay)
618 get("/", ActivityPubController, :relay)
619 end
620
621 scope "/", Pleroma.Web.ActivityPub do
622 pipe_through(:activitypub)
623 post("/inbox", ActivityPubController, :inbox)
624 post("/users/:nickname/inbox", ActivityPubController, :inbox)
625 end
626
627 scope "/.well-known", Pleroma.Web do
628 pipe_through(:well_known)
629
630 get("/host-meta", WebFinger.WebFingerController, :host_meta)
631 get("/webfinger", WebFinger.WebFingerController, :webfinger)
632 get("/nodeinfo", Nodeinfo.NodeinfoController, :schemas)
633 end
634
635 scope "/nodeinfo", Pleroma.Web do
636 get("/:version", Nodeinfo.NodeinfoController, :nodeinfo)
637 end
638
639 scope "/", Pleroma.Web.MastodonAPI do
640 pipe_through(:mastodon_html)
641
642 get("/web/login", MastodonAPIController, :login)
643 delete("/auth/sign_out", MastodonAPIController, :logout)
644
645 scope [] do
646 pipe_through(:oauth_read_or_unauthenticated)
647 get("/web/*path", MastodonAPIController, :index)
648 end
649 end
650
651 pipeline :remote_media do
652 end
653
654 scope "/proxy/", Pleroma.Web.MediaProxy do
655 pipe_through(:remote_media)
656
657 get("/:sig/:url", MediaProxyController, :remote)
658 get("/:sig/:url/:filename", MediaProxyController, :remote)
659 end
660
661 if Mix.env() == :dev do
662 scope "/dev" do
663 pipe_through([:mailbox_preview])
664
665 forward("/mailbox", Plug.Swoosh.MailboxPreview, base_path: "/dev/mailbox")
666 end
667 end
668
669 scope "/", Fallback do
670 get("/registration/:token", RedirectController, :registration_page)
671 get("/:maybe_nickname_or_id", RedirectController, :redirector_with_meta)
672 get("/*path", RedirectController, :redirector)
673
674 options("/*path", RedirectController, :empty)
675 end
676 end
677
678 defmodule Fallback.RedirectController do
679 use Pleroma.Web, :controller
680 alias Pleroma.User
681 alias Pleroma.Web.Metadata
682
683 def redirector(conn, _params, code \\ 200) do
684 conn
685 |> put_resp_content_type("text/html")
686 |> send_file(code, index_file_path())
687 end
688
689 def redirector_with_meta(conn, %{"maybe_nickname_or_id" => maybe_nickname_or_id} = params) do
690 with %User{} = user <- User.get_cached_by_nickname_or_id(maybe_nickname_or_id) do
691 redirector_with_meta(conn, %{user: user})
692 else
693 nil ->
694 redirector(conn, params)
695 end
696 end
697
698 def redirector_with_meta(conn, params) do
699 {:ok, index_content} = File.read(index_file_path())
700 tags = Metadata.build_tags(params)
701 response = String.replace(index_content, "<!--server-generated-meta-->", tags)
702
703 conn
704 |> put_resp_content_type("text/html")
705 |> send_resp(200, response)
706 end
707
708 def index_file_path do
709 Pleroma.Plugs.InstanceStatic.file_path("index.html")
710 end
711
712 def registration_page(conn, params) do
713 redirector(conn, params)
714 end
715
716 def empty(conn, _params) do
717 conn
718 |> put_status(204)
719 |> text("")
720 end
721 end