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