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