Merge branch 'feature/federator-behaviours' into 'develop'
[akkoma] / lib / pleroma / web / router.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.Router do
6 use Pleroma.Web, :router
7
8 pipeline :browser do
9 plug(:accepts, ["html"])
10 plug(:fetch_session)
11 end
12
13 pipeline :oauth do
14 plug(:fetch_session)
15 plug(Pleroma.Plugs.OAuthPlug)
16 end
17
18 pipeline :api do
19 plug(:accepts, ["json"])
20 plug(:fetch_session)
21 plug(Pleroma.Plugs.OAuthPlug)
22 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
23 plug(Pleroma.Plugs.UserFetcherPlug)
24 plug(Pleroma.Plugs.SessionAuthenticationPlug)
25 plug(Pleroma.Plugs.LegacyAuthenticationPlug)
26 plug(Pleroma.Plugs.AuthenticationPlug)
27 plug(Pleroma.Plugs.UserEnabledPlug)
28 plug(Pleroma.Plugs.SetUserSessionIdPlug)
29 plug(Pleroma.Plugs.EnsureUserKeyPlug)
30 end
31
32 pipeline :authenticated_api do
33 plug(:accepts, ["json"])
34 plug(:fetch_session)
35 plug(Pleroma.Plugs.OAuthPlug)
36 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
37 plug(Pleroma.Plugs.UserFetcherPlug)
38 plug(Pleroma.Plugs.SessionAuthenticationPlug)
39 plug(Pleroma.Plugs.LegacyAuthenticationPlug)
40 plug(Pleroma.Plugs.AuthenticationPlug)
41 plug(Pleroma.Plugs.UserEnabledPlug)
42 plug(Pleroma.Plugs.SetUserSessionIdPlug)
43 plug(Pleroma.Plugs.EnsureAuthenticatedPlug)
44 end
45
46 pipeline :admin_api do
47 plug(:accepts, ["json"])
48 plug(:fetch_session)
49 plug(Pleroma.Plugs.OAuthPlug)
50 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
51 plug(Pleroma.Plugs.UserFetcherPlug)
52 plug(Pleroma.Plugs.SessionAuthenticationPlug)
53 plug(Pleroma.Plugs.LegacyAuthenticationPlug)
54 plug(Pleroma.Plugs.AuthenticationPlug)
55 plug(Pleroma.Plugs.AdminSecretAuthenticationPlug)
56 plug(Pleroma.Plugs.UserEnabledPlug)
57 plug(Pleroma.Plugs.SetUserSessionIdPlug)
58 plug(Pleroma.Plugs.EnsureAuthenticatedPlug)
59 plug(Pleroma.Plugs.UserIsAdminPlug)
60 end
61
62 pipeline :mastodon_html do
63 plug(:accepts, ["html"])
64 plug(:fetch_session)
65 plug(Pleroma.Plugs.OAuthPlug)
66 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
67 plug(Pleroma.Plugs.UserFetcherPlug)
68 plug(Pleroma.Plugs.SessionAuthenticationPlug)
69 plug(Pleroma.Plugs.LegacyAuthenticationPlug)
70 plug(Pleroma.Plugs.AuthenticationPlug)
71 plug(Pleroma.Plugs.UserEnabledPlug)
72 plug(Pleroma.Plugs.SetUserSessionIdPlug)
73 plug(Pleroma.Plugs.EnsureUserKeyPlug)
74 end
75
76 pipeline :pleroma_html do
77 plug(:accepts, ["html"])
78 plug(:fetch_session)
79 plug(Pleroma.Plugs.OAuthPlug)
80 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
81 plug(Pleroma.Plugs.UserFetcherPlug)
82 plug(Pleroma.Plugs.SessionAuthenticationPlug)
83 plug(Pleroma.Plugs.AuthenticationPlug)
84 plug(Pleroma.Plugs.EnsureUserKeyPlug)
85 end
86
87 pipeline :oauth_read_or_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 post("/accounts", MastodonAPIController, :account_register)
389
390 get("/instance", MastodonAPIController, :masto_instance)
391 get("/instance/peers", MastodonAPIController, :peers)
392 post("/apps", MastodonAPIController, :create_app)
393 get("/apps/verify_credentials", MastodonAPIController, :verify_app_credentials)
394 get("/custom_emojis", MastodonAPIController, :custom_emojis)
395
396 get("/statuses/:id/card", MastodonAPIController, :status_card)
397
398 get("/statuses/:id/favourited_by", MastodonAPIController, :favourited_by)
399 get("/statuses/:id/reblogged_by", MastodonAPIController, :reblogged_by)
400
401 get("/trends", MastodonAPIController, :empty_array)
402
403 get("/accounts/search", MastodonAPIController, :account_search)
404
405 scope [] do
406 pipe_through(:oauth_read_or_unauthenticated)
407
408 get("/timelines/public", MastodonAPIController, :public_timeline)
409 get("/timelines/tag/:tag", MastodonAPIController, :hashtag_timeline)
410 get("/timelines/list/:list_id", MastodonAPIController, :list_timeline)
411
412 get("/statuses/:id", MastodonAPIController, :get_status)
413 get("/statuses/:id/context", MastodonAPIController, :get_context)
414
415 get("/accounts/:id/statuses", MastodonAPIController, :user_statuses)
416 get("/accounts/:id/followers", MastodonAPIController, :followers)
417 get("/accounts/:id/following", MastodonAPIController, :following)
418 get("/accounts/:id", MastodonAPIController, :user)
419
420 get("/search", MastodonAPIController, :search)
421
422 get("/pleroma/accounts/:id/favourites", MastodonAPIController, :user_favourites)
423 end
424 end
425
426 scope "/api/v2", Pleroma.Web.MastodonAPI do
427 pipe_through([:api, :oauth_read_or_unauthenticated])
428 get("/search", MastodonAPIController, :search2)
429 end
430
431 scope "/api", Pleroma.Web do
432 pipe_through(:config)
433
434 get("/help/test", TwitterAPI.UtilController, :help_test)
435 post("/help/test", TwitterAPI.UtilController, :help_test)
436 get("/statusnet/config", TwitterAPI.UtilController, :config)
437 get("/statusnet/version", TwitterAPI.UtilController, :version)
438 get("/pleroma/frontend_configurations", TwitterAPI.UtilController, :frontend_configurations)
439 end
440
441 scope "/api", Pleroma.Web do
442 pipe_through(:api)
443
444 post("/account/register", TwitterAPI.Controller, :register)
445 post("/account/password_reset", TwitterAPI.Controller, :password_reset)
446
447 post("/account/resend_confirmation_email", TwitterAPI.Controller, :resend_confirmation_email)
448
449 get(
450 "/account/confirm_email/:user_id/:token",
451 TwitterAPI.Controller,
452 :confirm_email,
453 as: :confirm_email
454 )
455
456 scope [] do
457 pipe_through(:oauth_read_or_unauthenticated)
458
459 get("/statuses/user_timeline", TwitterAPI.Controller, :user_timeline)
460 get("/qvitter/statuses/user_timeline", TwitterAPI.Controller, :user_timeline)
461 get("/users/show", TwitterAPI.Controller, :show_user)
462
463 get("/statuses/followers", TwitterAPI.Controller, :followers)
464 get("/statuses/friends", TwitterAPI.Controller, :friends)
465 get("/statuses/blocks", TwitterAPI.Controller, :blocks)
466 get("/statuses/show/:id", TwitterAPI.Controller, :fetch_status)
467 get("/statusnet/conversation/:id", TwitterAPI.Controller, :fetch_conversation)
468
469 get("/search", TwitterAPI.Controller, :search)
470 get("/statusnet/tags/timeline/:tag", TwitterAPI.Controller, :public_and_external_timeline)
471 end
472 end
473
474 scope "/api", Pleroma.Web do
475 pipe_through([:api, :oauth_read_or_unauthenticated])
476
477 get("/statuses/public_timeline", TwitterAPI.Controller, :public_timeline)
478
479 get(
480 "/statuses/public_and_external_timeline",
481 TwitterAPI.Controller,
482 :public_and_external_timeline
483 )
484
485 get("/statuses/networkpublic_timeline", TwitterAPI.Controller, :public_and_external_timeline)
486 end
487
488 scope "/api", Pleroma.Web, as: :twitter_api_search do
489 pipe_through([:api, :oauth_read_or_unauthenticated])
490 get("/pleroma/search_user", TwitterAPI.Controller, :search_user)
491 end
492
493 scope "/api", Pleroma.Web, as: :authenticated_twitter_api do
494 pipe_through(:authenticated_api)
495
496 get("/oauth_tokens", TwitterAPI.Controller, :oauth_tokens)
497 delete("/oauth_tokens/:id", TwitterAPI.Controller, :revoke_token)
498
499 scope [] do
500 pipe_through(:oauth_read)
501
502 get("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials)
503 post("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials)
504
505 get("/statuses/home_timeline", TwitterAPI.Controller, :friends_timeline)
506 get("/statuses/friends_timeline", TwitterAPI.Controller, :friends_timeline)
507 get("/statuses/mentions", TwitterAPI.Controller, :mentions_timeline)
508 get("/statuses/mentions_timeline", TwitterAPI.Controller, :mentions_timeline)
509 get("/statuses/dm_timeline", TwitterAPI.Controller, :dm_timeline)
510 get("/qvitter/statuses/notifications", TwitterAPI.Controller, :notifications)
511
512 get("/pleroma/friend_requests", TwitterAPI.Controller, :friend_requests)
513
514 get("/friends/ids", TwitterAPI.Controller, :friends_ids)
515 get("/friendships/no_retweets/ids", TwitterAPI.Controller, :empty_array)
516
517 get("/mutes/users/ids", TwitterAPI.Controller, :empty_array)
518 get("/qvitter/mutes", TwitterAPI.Controller, :raw_empty_array)
519
520 get("/externalprofile/show", TwitterAPI.Controller, :external_profile)
521
522 post("/qvitter/statuses/notifications/read", TwitterAPI.Controller, :notifications_read)
523 end
524
525 scope [] do
526 pipe_through(:oauth_write)
527
528 post("/account/update_profile", TwitterAPI.Controller, :update_profile)
529 post("/account/update_profile_banner", TwitterAPI.Controller, :update_banner)
530 post("/qvitter/update_background_image", TwitterAPI.Controller, :update_background)
531
532 post("/statuses/update", TwitterAPI.Controller, :status_update)
533 post("/statuses/retweet/:id", TwitterAPI.Controller, :retweet)
534 post("/statuses/unretweet/:id", TwitterAPI.Controller, :unretweet)
535 post("/statuses/destroy/:id", TwitterAPI.Controller, :delete_post)
536
537 post("/statuses/pin/:id", TwitterAPI.Controller, :pin)
538 post("/statuses/unpin/:id", TwitterAPI.Controller, :unpin)
539
540 post("/statusnet/media/upload", TwitterAPI.Controller, :upload)
541 post("/media/upload", TwitterAPI.Controller, :upload_json)
542 post("/media/metadata/create", TwitterAPI.Controller, :update_media)
543
544 post("/favorites/create/:id", TwitterAPI.Controller, :favorite)
545 post("/favorites/create", TwitterAPI.Controller, :favorite)
546 post("/favorites/destroy/:id", TwitterAPI.Controller, :unfavorite)
547
548 post("/qvitter/update_avatar", TwitterAPI.Controller, :update_avatar)
549 end
550
551 scope [] do
552 pipe_through(:oauth_follow)
553
554 post("/pleroma/friendships/approve", TwitterAPI.Controller, :approve_friend_request)
555 post("/pleroma/friendships/deny", TwitterAPI.Controller, :deny_friend_request)
556
557 post("/friendships/create", TwitterAPI.Controller, :follow)
558 post("/friendships/destroy", TwitterAPI.Controller, :unfollow)
559
560 post("/blocks/create", TwitterAPI.Controller, :block)
561 post("/blocks/destroy", TwitterAPI.Controller, :unblock)
562 end
563 end
564
565 pipeline :ap_relay do
566 plug(:accepts, ["activity+json", "json"])
567 end
568
569 pipeline :ostatus do
570 plug(:accepts, ["html", "xml", "atom", "activity+json", "json"])
571 end
572
573 pipeline :oembed do
574 plug(:accepts, ["json", "xml"])
575 end
576
577 scope "/", Pleroma.Web do
578 pipe_through(:ostatus)
579
580 get("/objects/:uuid", OStatus.OStatusController, :object)
581 get("/activities/:uuid", OStatus.OStatusController, :activity)
582 get("/notice/:id", OStatus.OStatusController, :notice)
583 get("/notice/:id/embed_player", OStatus.OStatusController, :notice_player)
584 get("/users/:nickname/feed", OStatus.OStatusController, :feed)
585 get("/users/:nickname", OStatus.OStatusController, :feed_redirect)
586
587 post("/users/:nickname/salmon", OStatus.OStatusController, :salmon_incoming)
588 post("/push/hub/:nickname", Websub.WebsubController, :websub_subscription_request)
589 get("/push/subscriptions/:id", Websub.WebsubController, :websub_subscription_confirmation)
590 post("/push/subscriptions/:id", Websub.WebsubController, :websub_incoming)
591 end
592
593 scope "/", Pleroma.Web do
594 pipe_through(:oembed)
595
596 get("/oembed", OEmbed.OEmbedController, :url)
597 end
598
599 pipeline :activitypub do
600 plug(:accepts, ["activity+json", "json"])
601 plug(Pleroma.Web.Plugs.HTTPSignaturePlug)
602 end
603
604 scope "/", Pleroma.Web.ActivityPub do
605 # XXX: not really ostatus
606 pipe_through(:ostatus)
607
608 get("/users/:nickname/followers", ActivityPubController, :followers)
609 get("/users/:nickname/following", ActivityPubController, :following)
610 get("/users/:nickname/outbox", ActivityPubController, :outbox)
611 get("/objects/:uuid/likes", ActivityPubController, :object_likes)
612 end
613
614 pipeline :activitypub_client do
615 plug(:accepts, ["activity+json", "json"])
616 plug(:fetch_session)
617 plug(Pleroma.Plugs.OAuthPlug)
618 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
619 plug(Pleroma.Plugs.UserFetcherPlug)
620 plug(Pleroma.Plugs.SessionAuthenticationPlug)
621 plug(Pleroma.Plugs.LegacyAuthenticationPlug)
622 plug(Pleroma.Plugs.AuthenticationPlug)
623 plug(Pleroma.Plugs.UserEnabledPlug)
624 plug(Pleroma.Plugs.SetUserSessionIdPlug)
625 plug(Pleroma.Plugs.EnsureUserKeyPlug)
626 end
627
628 scope "/", Pleroma.Web.ActivityPub do
629 pipe_through([:activitypub_client])
630
631 scope [] do
632 pipe_through(:oauth_read)
633 get("/api/ap/whoami", ActivityPubController, :whoami)
634 get("/users/:nickname/inbox", ActivityPubController, :read_inbox)
635 end
636
637 scope [] do
638 pipe_through(:oauth_write)
639 post("/users/:nickname/outbox", ActivityPubController, :update_outbox)
640 end
641 end
642
643 scope "/relay", Pleroma.Web.ActivityPub do
644 pipe_through(:ap_relay)
645 get("/", ActivityPubController, :relay)
646 end
647
648 scope "/", Pleroma.Web.ActivityPub do
649 pipe_through(:activitypub)
650 post("/inbox", ActivityPubController, :inbox)
651 post("/users/:nickname/inbox", ActivityPubController, :inbox)
652 end
653
654 scope "/.well-known", Pleroma.Web do
655 pipe_through(:well_known)
656
657 get("/host-meta", WebFinger.WebFingerController, :host_meta)
658 get("/webfinger", WebFinger.WebFingerController, :webfinger)
659 get("/nodeinfo", Nodeinfo.NodeinfoController, :schemas)
660 end
661
662 scope "/nodeinfo", Pleroma.Web do
663 get("/:version", Nodeinfo.NodeinfoController, :nodeinfo)
664 end
665
666 scope "/", Pleroma.Web.MastodonAPI do
667 pipe_through(:mastodon_html)
668
669 get("/web/login", MastodonAPIController, :login)
670 delete("/auth/sign_out", MastodonAPIController, :logout)
671
672 scope [] do
673 pipe_through(:oauth_read_or_unauthenticated)
674 get("/web/*path", MastodonAPIController, :index)
675 end
676 end
677
678 pipeline :remote_media do
679 end
680
681 scope "/proxy/", Pleroma.Web.MediaProxy do
682 pipe_through(:remote_media)
683
684 get("/:sig/:url", MediaProxyController, :remote)
685 get("/:sig/:url/:filename", MediaProxyController, :remote)
686 end
687
688 if Mix.env() == :dev do
689 scope "/dev" do
690 pipe_through([:mailbox_preview])
691
692 forward("/mailbox", Plug.Swoosh.MailboxPreview, base_path: "/dev/mailbox")
693 end
694 end
695
696 scope "/", Fallback do
697 get("/registration/:token", RedirectController, :registration_page)
698 get("/:maybe_nickname_or_id", RedirectController, :redirector_with_meta)
699 get("/*path", RedirectController, :redirector)
700
701 options("/*path", RedirectController, :empty)
702 end
703 end
704
705 defmodule Fallback.RedirectController do
706 use Pleroma.Web, :controller
707 alias Pleroma.User
708 alias Pleroma.Web.Metadata
709
710 def redirector(conn, _params, code \\ 200) do
711 conn
712 |> put_resp_content_type("text/html")
713 |> send_file(code, index_file_path())
714 end
715
716 def redirector_with_meta(conn, %{"maybe_nickname_or_id" => maybe_nickname_or_id} = params) do
717 with %User{} = user <- User.get_cached_by_nickname_or_id(maybe_nickname_or_id) do
718 redirector_with_meta(conn, %{user: user})
719 else
720 nil ->
721 redirector(conn, params)
722 end
723 end
724
725 def redirector_with_meta(conn, params) do
726 {:ok, index_content} = File.read(index_file_path())
727 tags = Metadata.build_tags(params)
728 response = String.replace(index_content, "<!--server-generated-meta-->", tags)
729
730 conn
731 |> put_resp_content_type("text/html")
732 |> send_resp(200, response)
733 end
734
735 def index_file_path do
736 Pleroma.Plugs.InstanceStatic.file_path("index.html")
737 end
738
739 def registration_page(conn, params) do
740 redirector(conn, params)
741 end
742
743 def empty(conn, _params) do
744 conn
745 |> put_status(204)
746 |> text("")
747 end
748 end