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