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