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