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