X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Fweb%2Ffallback_redirect_controller.ex;h=431ad5485b2371fbf267692ab12dd54c90fc7198;hb=4bfad0b483957acf755a043f33799742997da859;hp=5fbf3695f4072027d865fc6e29e1c9d7663f68c8;hpb=cc6c0b4ba6762e6a9b0a90c3dcda3f95283eb22a;p=akkoma
diff --git a/lib/pleroma/web/fallback_redirect_controller.ex b/lib/pleroma/web/fallback_redirect_controller.ex
index 5fbf3695f..431ad5485 100644
--- a/lib/pleroma/web/fallback_redirect_controller.ex
+++ b/lib/pleroma/web/fallback_redirect_controller.ex
@@ -1,12 +1,15 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors
+# Copyright © 2017-2020 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Fallback.RedirectController do
use Pleroma.Web, :controller
+
require Logger
+
alias Pleroma.User
alias Pleroma.Web.Metadata
+ alias Pleroma.Web.Preload
def api_not_implemented(conn, _params) do
conn
@@ -14,16 +17,7 @@ defmodule Fallback.RedirectController do
|> json(%{error: "Not implemented"})
end
- def redirector(conn, _params, code \\ 200)
-
- # redirect to admin section
- # /pleroma/admin -> /pleroma/admin/
- #
- def redirector(conn, %{"path" => ["pleroma", "admin"]} = _, _code) do
- redirect(conn, to: "/pleroma/admin/")
- end
-
- def redirector(conn, _params, code) do
+ def redirector(conn, _params, code \\ 200) do
conn
|> put_resp_content_type("text/html")
|> send_file(code, index_file_path())
@@ -41,28 +35,33 @@ defmodule Fallback.RedirectController do
def redirector_with_meta(conn, params) do
{:ok, index_content} = File.read(index_file_path())
- tags =
- try do
- Metadata.build_tags(params)
- rescue
- e ->
- Logger.error(
- "Metadata rendering for #{conn.request_path} failed.\n" <>
- Exception.format(:error, e, __STACKTRACE__)
- )
-
- ""
- end
+ tags = build_tags(conn, params)
+ preloads = preload_data(conn, params)
- response = String.replace(index_content, "", tags)
+ response =
+ index_content
+ |> String.replace("", tags <> preloads)
conn
|> put_resp_content_type("text/html")
|> send_resp(200, response)
end
- def index_file_path do
- Pleroma.Plugs.InstanceStatic.file_path("index.html")
+ def redirector_with_preload(conn, %{"path" => ["pleroma", "admin"]}) do
+ redirect(conn, to: "/pleroma/admin/")
+ end
+
+ def redirector_with_preload(conn, params) do
+ {:ok, index_content} = File.read(index_file_path())
+ preloads = preload_data(conn, params)
+
+ response =
+ index_content
+ |> String.replace("", preloads)
+
+ conn
+ |> put_resp_content_type("text/html")
+ |> send_resp(200, response)
end
def registration_page(conn, params) do
@@ -74,4 +73,36 @@ defmodule Fallback.RedirectController do
|> put_status(204)
|> text("")
end
+
+ defp index_file_path do
+ Pleroma.Plugs.InstanceStatic.file_path("index.html")
+ end
+
+ defp build_tags(conn, params) do
+ try do
+ Metadata.build_tags(params)
+ rescue
+ e ->
+ Logger.error(
+ "Metadata rendering for #{conn.request_path} failed.\n" <>
+ Exception.format(:error, e, __STACKTRACE__)
+ )
+
+ ""
+ end
+ end
+
+ defp preload_data(conn, params) do
+ try do
+ Preload.build_tags(conn, params)
+ rescue
+ e ->
+ Logger.error(
+ "Preloading for #{conn.request_path} failed.\n" <>
+ Exception.format(:error, e, __STACKTRACE__)
+ )
+
+ ""
+ end
+ end
end