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