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