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