[#468] Prototype of OAuth2 scopes support. TwitterAPI scope restrictions.
[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 :api do
9 plug(:accepts, ["json"])
10 plug(:fetch_session)
11 plug(Pleroma.Plugs.OAuthPlug)
12 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
13 plug(Pleroma.Plugs.UserFetcherPlug)
14 plug(Pleroma.Plugs.SessionAuthenticationPlug)
15 plug(Pleroma.Plugs.LegacyAuthenticationPlug)
16 plug(Pleroma.Plugs.AuthenticationPlug)
17 plug(Pleroma.Plugs.UserEnabledPlug)
18 plug(Pleroma.Plugs.SetUserSessionIdPlug)
19 plug(Pleroma.Plugs.EnsureUserKeyPlug)
20 end
21
22 pipeline :authenticated_api do
23 plug(:accepts, ["json"])
24 plug(:fetch_session)
25 plug(Pleroma.Plugs.OAuthPlug)
26 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
27 plug(Pleroma.Plugs.UserFetcherPlug)
28 plug(Pleroma.Plugs.SessionAuthenticationPlug)
29 plug(Pleroma.Plugs.LegacyAuthenticationPlug)
30 plug(Pleroma.Plugs.AuthenticationPlug)
31 plug(Pleroma.Plugs.UserEnabledPlug)
32 plug(Pleroma.Plugs.SetUserSessionIdPlug)
33 plug(Pleroma.Plugs.EnsureAuthenticatedPlug)
34 end
35
36 pipeline :admin_api do
37 plug(:accepts, ["json"])
38 plug(:fetch_session)
39 plug(Pleroma.Plugs.OAuthPlug)
40 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
41 plug(Pleroma.Plugs.UserFetcherPlug)
42 plug(Pleroma.Plugs.SessionAuthenticationPlug)
43 plug(Pleroma.Plugs.LegacyAuthenticationPlug)
44 plug(Pleroma.Plugs.AuthenticationPlug)
45 plug(Pleroma.Plugs.AdminSecretAuthenticationPlug)
46 plug(Pleroma.Plugs.UserEnabledPlug)
47 plug(Pleroma.Plugs.SetUserSessionIdPlug)
48 plug(Pleroma.Plugs.EnsureAuthenticatedPlug)
49 plug(Pleroma.Plugs.UserIsAdminPlug)
50 end
51
52 pipeline :mastodon_html do
53 plug(:accepts, ["html"])
54 plug(:fetch_session)
55 plug(Pleroma.Plugs.OAuthPlug)
56 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
57 plug(Pleroma.Plugs.UserFetcherPlug)
58 plug(Pleroma.Plugs.SessionAuthenticationPlug)
59 plug(Pleroma.Plugs.LegacyAuthenticationPlug)
60 plug(Pleroma.Plugs.AuthenticationPlug)
61 plug(Pleroma.Plugs.UserEnabledPlug)
62 plug(Pleroma.Plugs.SetUserSessionIdPlug)
63 plug(Pleroma.Plugs.EnsureUserKeyPlug)
64 end
65
66 pipeline :pleroma_html do
67 plug(:accepts, ["html"])
68 plug(:fetch_session)
69 plug(Pleroma.Plugs.OAuthPlug)
70 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
71 plug(Pleroma.Plugs.UserFetcherPlug)
72 plug(Pleroma.Plugs.SessionAuthenticationPlug)
73 plug(Pleroma.Plugs.AuthenticationPlug)
74 plug(Pleroma.Plugs.EnsureUserKeyPlug)
75 end
76
77 pipeline :oauth_read do
78 plug(Pleroma.Plugs.OAuthScopesPlug, %{required_scopes: ["read"]})
79 end
80
81 pipeline :oauth_write do
82 plug(Pleroma.Plugs.OAuthScopesPlug, %{required_scopes: ["write"]})
83 end
84
85 pipeline :oauth_follow do
86 plug(Pleroma.Plugs.OAuthScopesPlug, %{required_scopes: ["follow"]})
87 end
88
89 pipeline :well_known do
90 plug(:accepts, ["json", "jrd+json", "xml", "xrd+xml"])
91 end
92
93 pipeline :config do
94 plug(:accepts, ["json", "xml"])
95 end
96
97 pipeline :oauth do
98 plug(:accepts, ["html", "json"])
99 end
100
101 pipeline :pleroma_api do
102 plug(:accepts, ["html", "json"])
103 end
104
105 pipeline :mailbox_preview do
106 plug(:accepts, ["html"])
107
108 plug(:put_secure_browser_headers, %{
109 "content-security-policy" =>
110 "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline' 'unsafe-eval'"
111 })
112 end
113
114 scope "/api/pleroma", Pleroma.Web.TwitterAPI do
115 pipe_through(:pleroma_api)
116 get("/password_reset/:token", UtilController, :show_password_reset)
117 post("/password_reset", UtilController, :password_reset)
118 get("/emoji", UtilController, :emoji)
119 get("/captcha", UtilController, :captcha)
120 end
121
122 scope "/api/pleroma", Pleroma.Web do
123 pipe_through(:pleroma_api)
124 post("/uploader_callback/:upload_path", UploaderController, :callback)
125 end
126
127 scope "/api/pleroma/admin", Pleroma.Web.AdminAPI do
128 pipe_through(:admin_api)
129 delete("/user", AdminAPIController, :user_delete)
130 post("/user", AdminAPIController, :user_create)
131 put("/users/tag", AdminAPIController, :tag_users)
132 delete("/users/tag", AdminAPIController, :untag_users)
133
134 get("/permission_group/:nickname", AdminAPIController, :right_get)
135 get("/permission_group/:nickname/:permission_group", AdminAPIController, :right_get)
136 post("/permission_group/:nickname/:permission_group", AdminAPIController, :right_add)
137 delete("/permission_group/:nickname/:permission_group", AdminAPIController, :right_delete)
138
139 post("/relay", AdminAPIController, :relay_follow)
140 delete("/relay", AdminAPIController, :relay_unfollow)
141
142 get("/invite_token", AdminAPIController, :get_invite_token)
143 post("/email_invite", AdminAPIController, :email_invite)
144
145 get("/password_reset", AdminAPIController, :get_password_reset)
146 end
147
148 scope "/", Pleroma.Web.TwitterAPI do
149 pipe_through(:pleroma_html)
150 get("/ostatus_subscribe", UtilController, :remote_follow)
151 post("/ostatus_subscribe", UtilController, :do_remote_follow)
152 post("/main/ostatus", UtilController, :remote_subscribe)
153 end
154
155 scope "/api/pleroma", Pleroma.Web.TwitterAPI do
156 pipe_through(:authenticated_api)
157 post("/blocks_import", UtilController, :blocks_import)
158 post("/follow_import", UtilController, :follow_import)
159 post("/change_password", UtilController, :change_password)
160 post("/delete_account", UtilController, :delete_account)
161 end
162
163 scope "/oauth", Pleroma.Web.OAuth do
164 get("/authorize", OAuthController, :authorize)
165 post("/authorize", OAuthController, :create_authorization)
166 post("/token", OAuthController, :token_exchange)
167 post("/revoke", OAuthController, :token_revoke)
168 end
169
170 scope "/api/v1", Pleroma.Web.MastodonAPI do
171 pipe_through(:authenticated_api)
172
173 patch("/accounts/update_credentials", MastodonAPIController, :update_credentials)
174 get("/accounts/verify_credentials", MastodonAPIController, :verify_credentials)
175 get("/accounts/relationships", MastodonAPIController, :relationships)
176 get("/accounts/search", MastodonAPIController, :account_search)
177 post("/accounts/:id/follow", MastodonAPIController, :follow)
178 post("/accounts/:id/unfollow", MastodonAPIController, :unfollow)
179 post("/accounts/:id/block", MastodonAPIController, :block)
180 post("/accounts/:id/unblock", MastodonAPIController, :unblock)
181 post("/accounts/:id/mute", MastodonAPIController, :relationship_noop)
182 post("/accounts/:id/unmute", MastodonAPIController, :relationship_noop)
183 get("/accounts/:id/lists", MastodonAPIController, :account_lists)
184
185 get("/follow_requests", MastodonAPIController, :follow_requests)
186 post("/follow_requests/:id/authorize", MastodonAPIController, :authorize_follow_request)
187 post("/follow_requests/:id/reject", MastodonAPIController, :reject_follow_request)
188
189 post("/follows", MastodonAPIController, :follow)
190
191 get("/blocks", MastodonAPIController, :blocks)
192
193 get("/mutes", MastodonAPIController, :empty_array)
194
195 get("/timelines/home", MastodonAPIController, :home_timeline)
196
197 get("/timelines/direct", MastodonAPIController, :dm_timeline)
198
199 get("/favourites", MastodonAPIController, :favourites)
200 get("/bookmarks", MastodonAPIController, :bookmarks)
201
202 post("/statuses", MastodonAPIController, :post_status)
203 delete("/statuses/:id", MastodonAPIController, :delete_status)
204
205 post("/statuses/:id/reblog", MastodonAPIController, :reblog_status)
206 post("/statuses/:id/unreblog", MastodonAPIController, :unreblog_status)
207 post("/statuses/:id/favourite", MastodonAPIController, :fav_status)
208 post("/statuses/:id/unfavourite", MastodonAPIController, :unfav_status)
209 post("/statuses/:id/pin", MastodonAPIController, :pin_status)
210 post("/statuses/:id/unpin", MastodonAPIController, :unpin_status)
211 post("/statuses/:id/bookmark", MastodonAPIController, :bookmark_status)
212 post("/statuses/:id/unbookmark", MastodonAPIController, :unbookmark_status)
213
214 post("/notifications/clear", MastodonAPIController, :clear_notifications)
215 post("/notifications/dismiss", MastodonAPIController, :dismiss_notification)
216 get("/notifications", MastodonAPIController, :notifications)
217 get("/notifications/:id", MastodonAPIController, :get_notification)
218
219 post("/media", MastodonAPIController, :upload)
220 put("/media/:id", MastodonAPIController, :update_media)
221
222 get("/lists", MastodonAPIController, :get_lists)
223 get("/lists/:id", MastodonAPIController, :get_list)
224 delete("/lists/:id", MastodonAPIController, :delete_list)
225 post("/lists", MastodonAPIController, :create_list)
226 put("/lists/:id", MastodonAPIController, :rename_list)
227 get("/lists/:id/accounts", MastodonAPIController, :list_accounts)
228 post("/lists/:id/accounts", MastodonAPIController, :add_to_list)
229 delete("/lists/:id/accounts", MastodonAPIController, :remove_from_list)
230
231 get("/domain_blocks", MastodonAPIController, :domain_blocks)
232 post("/domain_blocks", MastodonAPIController, :block_domain)
233 delete("/domain_blocks", MastodonAPIController, :unblock_domain)
234
235 get("/filters", MastodonAPIController, :get_filters)
236 post("/filters", MastodonAPIController, :create_filter)
237 get("/filters/:id", MastodonAPIController, :get_filter)
238 put("/filters/:id", MastodonAPIController, :update_filter)
239 delete("/filters/:id", MastodonAPIController, :delete_filter)
240
241 post("/push/subscription", MastodonAPIController, :create_push_subscription)
242 get("/push/subscription", MastodonAPIController, :get_push_subscription)
243 put("/push/subscription", MastodonAPIController, :update_push_subscription)
244 delete("/push/subscription", MastodonAPIController, :delete_push_subscription)
245
246 get("/suggestions", MastodonAPIController, :suggestions)
247
248 get("/endorsements", MastodonAPIController, :empty_array)
249 end
250
251 scope "/api/web", Pleroma.Web.MastodonAPI do
252 pipe_through(:authenticated_api)
253
254 put("/settings", MastodonAPIController, :put_settings)
255 end
256
257 scope "/api/v1", Pleroma.Web.MastodonAPI do
258 pipe_through(:api)
259 get("/instance", MastodonAPIController, :masto_instance)
260 get("/instance/peers", MastodonAPIController, :peers)
261 post("/apps", MastodonAPIController, :create_app)
262 get("/custom_emojis", MastodonAPIController, :custom_emojis)
263
264 get("/timelines/public", MastodonAPIController, :public_timeline)
265 get("/timelines/tag/:tag", MastodonAPIController, :hashtag_timeline)
266 get("/timelines/list/:list_id", MastodonAPIController, :list_timeline)
267
268 get("/statuses/:id", MastodonAPIController, :get_status)
269 get("/statuses/:id/context", MastodonAPIController, :get_context)
270 get("/statuses/:id/card", MastodonAPIController, :status_card)
271 get("/statuses/:id/favourited_by", MastodonAPIController, :favourited_by)
272 get("/statuses/:id/reblogged_by", MastodonAPIController, :reblogged_by)
273
274 get("/accounts/:id/statuses", MastodonAPIController, :user_statuses)
275 get("/accounts/:id/followers", MastodonAPIController, :followers)
276 get("/accounts/:id/following", MastodonAPIController, :following)
277 get("/accounts/:id", MastodonAPIController, :user)
278
279 get("/trends", MastodonAPIController, :empty_array)
280
281 get("/search", MastodonAPIController, :search)
282 end
283
284 scope "/api/v2", Pleroma.Web.MastodonAPI do
285 pipe_through(:api)
286 get("/search", MastodonAPIController, :search2)
287 end
288
289 scope "/api", Pleroma.Web do
290 pipe_through(:config)
291
292 get("/help/test", TwitterAPI.UtilController, :help_test)
293 post("/help/test", TwitterAPI.UtilController, :help_test)
294 get("/statusnet/config", TwitterAPI.UtilController, :config)
295 get("/statusnet/version", TwitterAPI.UtilController, :version)
296 get("/pleroma/frontend_configurations", TwitterAPI.UtilController, :frontend_configurations)
297 end
298
299 scope "/api", Pleroma.Web do
300 pipe_through(:api)
301
302 get("/statuses/user_timeline", TwitterAPI.Controller, :user_timeline)
303 get("/qvitter/statuses/user_timeline", TwitterAPI.Controller, :user_timeline)
304 get("/users/show", TwitterAPI.Controller, :show_user)
305
306 get("/statuses/followers", TwitterAPI.Controller, :followers)
307 get("/statuses/friends", TwitterAPI.Controller, :friends)
308 get("/statuses/blocks", TwitterAPI.Controller, :blocks)
309 get("/statuses/show/:id", TwitterAPI.Controller, :fetch_status)
310 get("/statusnet/conversation/:id", TwitterAPI.Controller, :fetch_conversation)
311
312 post("/account/register", TwitterAPI.Controller, :register)
313 post("/account/password_reset", TwitterAPI.Controller, :password_reset)
314
315 get(
316 "/account/confirm_email/:user_id/:token",
317 TwitterAPI.Controller,
318 :confirm_email,
319 as: :confirm_email
320 )
321
322 post("/account/resend_confirmation_email", TwitterAPI.Controller, :resend_confirmation_email)
323
324 get("/search", TwitterAPI.Controller, :search)
325 get("/statusnet/tags/timeline/:tag", TwitterAPI.Controller, :public_and_external_timeline)
326 end
327
328 scope "/api", Pleroma.Web do
329 pipe_through(:api)
330
331 get("/statuses/public_timeline", TwitterAPI.Controller, :public_timeline)
332
333 get(
334 "/statuses/public_and_external_timeline",
335 TwitterAPI.Controller,
336 :public_and_external_timeline
337 )
338
339 get("/statuses/networkpublic_timeline", TwitterAPI.Controller, :public_and_external_timeline)
340 end
341
342 scope "/api", Pleroma.Web, as: :twitter_api_search do
343 pipe_through(:api)
344 get("/pleroma/search_user", TwitterAPI.Controller, :search_user)
345 end
346
347 scope "/api", Pleroma.Web, as: :authenticated_twitter_api do
348 pipe_through(:authenticated_api)
349
350 get("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials)
351 post("/account/verify_credentials", TwitterAPI.Controller, :verify_credentials)
352
353 scope [] do
354 pipe_through(:oauth_read)
355
356 get("/statuses/home_timeline", TwitterAPI.Controller, :friends_timeline)
357 get("/statuses/friends_timeline", TwitterAPI.Controller, :friends_timeline)
358 get("/statuses/mentions", TwitterAPI.Controller, :mentions_timeline)
359 get("/statuses/mentions_timeline", TwitterAPI.Controller, :mentions_timeline)
360 get("/statuses/dm_timeline", TwitterAPI.Controller, :dm_timeline)
361 get("/qvitter/statuses/notifications", TwitterAPI.Controller, :notifications)
362
363 get("/pleroma/friend_requests", TwitterAPI.Controller, :friend_requests)
364
365 get("/friends/ids", TwitterAPI.Controller, :friends_ids)
366 get("/friendships/no_retweets/ids", TwitterAPI.Controller, :empty_array)
367
368 get("/mutes/users/ids", TwitterAPI.Controller, :empty_array)
369 get("/qvitter/mutes", TwitterAPI.Controller, :raw_empty_array)
370
371 get("/externalprofile/show", TwitterAPI.Controller, :external_profile)
372
373 post("/qvitter/statuses/notifications/read", TwitterAPI.Controller, :notifications_read)
374 end
375
376 scope [] do
377 pipe_through(:oauth_write)
378
379 post("/account/update_profile", TwitterAPI.Controller, :update_profile)
380 post("/account/update_profile_banner", TwitterAPI.Controller, :update_banner)
381 post("/qvitter/update_background_image", TwitterAPI.Controller, :update_background)
382
383 post("/statuses/update", TwitterAPI.Controller, :status_update)
384 post("/statuses/retweet/:id", TwitterAPI.Controller, :retweet)
385 post("/statuses/unretweet/:id", TwitterAPI.Controller, :unretweet)
386 post("/statuses/destroy/:id", TwitterAPI.Controller, :delete_post)
387
388 post("/statuses/pin/:id", TwitterAPI.Controller, :pin)
389 post("/statuses/unpin/:id", TwitterAPI.Controller, :unpin)
390
391 post("/statusnet/media/upload", TwitterAPI.Controller, :upload)
392 post("/media/upload", TwitterAPI.Controller, :upload_json)
393 post("/media/metadata/create", TwitterAPI.Controller, :update_media)
394
395 post("/favorites/create/:id", TwitterAPI.Controller, :favorite)
396 post("/favorites/create", TwitterAPI.Controller, :favorite)
397 post("/favorites/destroy/:id", TwitterAPI.Controller, :unfavorite)
398
399 post("/qvitter/update_avatar", TwitterAPI.Controller, :update_avatar)
400 end
401
402 scope [] do
403 pipe_through(:oauth_follow)
404
405 post("/pleroma/friendships/approve", TwitterAPI.Controller, :approve_friend_request)
406 post("/pleroma/friendships/deny", TwitterAPI.Controller, :deny_friend_request)
407
408 post("/friendships/create", TwitterAPI.Controller, :follow)
409 post("/friendships/destroy", TwitterAPI.Controller, :unfollow)
410
411 post("/blocks/create", TwitterAPI.Controller, :block)
412 post("/blocks/destroy", TwitterAPI.Controller, :unblock)
413 end
414 end
415
416 pipeline :ap_relay do
417 plug(:accepts, ["activity+json"])
418 end
419
420 pipeline :ostatus do
421 plug(:accepts, ["html", "xml", "atom", "activity+json"])
422 end
423
424 pipeline :oembed do
425 plug(:accepts, ["json", "xml"])
426 end
427
428 scope "/", Pleroma.Web do
429 pipe_through(:ostatus)
430
431 get("/objects/:uuid", OStatus.OStatusController, :object)
432 get("/activities/:uuid", OStatus.OStatusController, :activity)
433 get("/notice/:id", OStatus.OStatusController, :notice)
434 get("/users/:nickname/feed", OStatus.OStatusController, :feed)
435 get("/users/:nickname", OStatus.OStatusController, :feed_redirect)
436
437 post("/users/:nickname/salmon", OStatus.OStatusController, :salmon_incoming)
438 post("/push/hub/:nickname", Websub.WebsubController, :websub_subscription_request)
439 get("/push/subscriptions/:id", Websub.WebsubController, :websub_subscription_confirmation)
440 post("/push/subscriptions/:id", Websub.WebsubController, :websub_incoming)
441 end
442
443 scope "/", Pleroma.Web do
444 pipe_through(:oembed)
445
446 get("/oembed", OEmbed.OEmbedController, :url)
447 end
448
449 pipeline :activitypub do
450 plug(:accepts, ["activity+json"])
451 plug(Pleroma.Web.Plugs.HTTPSignaturePlug)
452 end
453
454 scope "/", Pleroma.Web.ActivityPub do
455 # XXX: not really ostatus
456 pipe_through(:ostatus)
457
458 get("/users/:nickname/followers", ActivityPubController, :followers)
459 get("/users/:nickname/following", ActivityPubController, :following)
460 get("/users/:nickname/outbox", ActivityPubController, :outbox)
461 get("/objects/:uuid/likes", ActivityPubController, :object_likes)
462 end
463
464 pipeline :activitypub_client do
465 plug(:accepts, ["activity+json"])
466 plug(:fetch_session)
467 plug(Pleroma.Plugs.OAuthPlug)
468 plug(Pleroma.Plugs.BasicAuthDecoderPlug)
469 plug(Pleroma.Plugs.UserFetcherPlug)
470 plug(Pleroma.Plugs.SessionAuthenticationPlug)
471 plug(Pleroma.Plugs.LegacyAuthenticationPlug)
472 plug(Pleroma.Plugs.AuthenticationPlug)
473 plug(Pleroma.Plugs.UserEnabledPlug)
474 plug(Pleroma.Plugs.SetUserSessionIdPlug)
475 plug(Pleroma.Plugs.EnsureUserKeyPlug)
476 end
477
478 scope "/", Pleroma.Web.ActivityPub do
479 pipe_through([:activitypub_client])
480
481 get("/api/ap/whoami", ActivityPubController, :whoami)
482 get("/users/:nickname/inbox", ActivityPubController, :read_inbox)
483 post("/users/:nickname/outbox", ActivityPubController, :update_outbox)
484 end
485
486 scope "/relay", Pleroma.Web.ActivityPub do
487 pipe_through(:ap_relay)
488 get("/", ActivityPubController, :relay)
489 end
490
491 scope "/", Pleroma.Web.ActivityPub do
492 pipe_through(:activitypub)
493 post("/users/:nickname/inbox", ActivityPubController, :inbox)
494 post("/inbox", ActivityPubController, :inbox)
495 end
496
497 scope "/.well-known", Pleroma.Web do
498 pipe_through(:well_known)
499
500 get("/host-meta", WebFinger.WebFingerController, :host_meta)
501 get("/webfinger", WebFinger.WebFingerController, :webfinger)
502 get("/nodeinfo", Nodeinfo.NodeinfoController, :schemas)
503 end
504
505 scope "/nodeinfo", Pleroma.Web do
506 get("/:version", Nodeinfo.NodeinfoController, :nodeinfo)
507 end
508
509 scope "/", Pleroma.Web.MastodonAPI do
510 pipe_through(:mastodon_html)
511
512 get("/web/login", MastodonAPIController, :login)
513 post("/web/login", MastodonAPIController, :login_post)
514 get("/web/*path", MastodonAPIController, :index)
515 delete("/auth/sign_out", MastodonAPIController, :logout)
516 end
517
518 pipeline :remote_media do
519 end
520
521 scope "/proxy/", Pleroma.Web.MediaProxy do
522 pipe_through(:remote_media)
523 get("/:sig/:url", MediaProxyController, :remote)
524 get("/:sig/:url/:filename", MediaProxyController, :remote)
525 end
526
527 if Mix.env() == :dev do
528 scope "/dev" do
529 pipe_through([:mailbox_preview])
530
531 forward("/mailbox", Plug.Swoosh.MailboxPreview, base_path: "/dev/mailbox")
532 end
533 end
534
535 scope "/", Fallback do
536 get("/registration/:token", RedirectController, :registration_page)
537 get("/:maybe_nickname_or_id", RedirectController, :redirector_with_meta)
538 get("/*path", RedirectController, :redirector)
539
540 options("/*path", RedirectController, :empty)
541 end
542 end
543
544 defmodule Fallback.RedirectController do
545 use Pleroma.Web, :controller
546 alias Pleroma.Web.Metadata
547 alias Pleroma.User
548
549 def redirector(conn, _params, code \\ 200) do
550 conn
551 |> put_resp_content_type("text/html")
552 |> send_file(code, index_file_path())
553 end
554
555 def redirector_with_meta(conn, %{"maybe_nickname_or_id" => maybe_nickname_or_id} = params) do
556 with %User{} = user <- User.get_cached_by_nickname_or_id(maybe_nickname_or_id) do
557 redirector_with_meta(conn, %{user: user})
558 else
559 nil ->
560 redirector(conn, params)
561 end
562 end
563
564 def redirector_with_meta(conn, params) do
565 {:ok, index_content} = File.read(index_file_path())
566 tags = Metadata.build_tags(params)
567 response = String.replace(index_content, "<!--server-generated-meta-->", tags)
568
569 conn
570 |> put_resp_content_type("text/html")
571 |> send_resp(200, response)
572 end
573
574 def index_file_path do
575 Pleroma.Plugs.InstanceStatic.file_path("index.html")
576 end
577
578 def registration_page(conn, params) do
579 redirector(conn, params)
580 end
581
582 def empty(conn, _params) do
583 conn
584 |> put_status(204)
585 |> text("")
586 end
587 end