aboutsummaryrefslogtreecommitdiff
path: root/lib/pleroma/frontend.ex
diff options
context:
space:
mode:
authorRoman Chvanikov <chvanikoff@pm.me>2020-07-10 23:05:07 +0300
committerRoman Chvanikov <chvanikoff@pm.me>2020-07-10 23:05:07 +0300
commitbb693768ff6f6afcb0b888b5a39100c6ff41f6bf (patch)
treec98faa365dfed7e4f408b5b527bed4636d99e472 /lib/pleroma/frontend.ex
parent6f0ac38f1d59264086e40392a59a1d753bd9b356 (diff)
downloadpleroma-bb693768ff6f6afcb0b888b5a39100c6ff41f6bf.tar.gz
Partially fix tests
Diffstat (limited to 'lib/pleroma/frontend.ex')
-rw-r--r--lib/pleroma/frontend.ex37
1 files changed, 37 insertions, 0 deletions
diff --git a/lib/pleroma/frontend.ex b/lib/pleroma/frontend.ex
index b344edd9e..941e2cfe9 100644
--- a/lib/pleroma/frontend.ex
+++ b/lib/pleroma/frontend.ex
@@ -29,4 +29,41 @@ defmodule Pleroma.Frontend do
static: fe_config[:static] || false
}
end
+
+ @doc """
+ Returns path to index.html file for the frontend from the given config.
+ If config is not provided, config for the `:primary` frontend is fetched and used.
+ If index.html file is not found for the requested frontend, the function fallback
+ to looking the file at instance static directory and then, in case of failure,
+ in priv/static directory.
+ Path returned in case of success is guaranteed to be existing file.
+ """
+ @spec fe_file_path(String.t(), map()) :: {:ok, String.t()} | {:error, String.t()}
+ def fe_file_path(filename, config \\ nil) do
+ %{"name" => name, "ref" => ref} =
+ with nil <- config do
+ get_primary_fe_opts()[:config]
+ end
+
+ instance_base_path = Pleroma.Config.get([:instance, :static_dir], "instance/static/")
+
+ frontend_path = Path.join([instance_base_path, "frontends", name, ref, filename])
+ instance_path = Path.join([instance_base_path, filename])
+ priv_path = Application.app_dir(:pleroma, ["priv", "static", filename])
+
+ cond do
+ File.exists?(instance_path) ->
+ {:ok, instance_path}
+
+ File.exists?(frontend_path) ->
+ {:ok, frontend_path}
+
+ File.exists?(priv_path) ->
+ {:ok, priv_path}
+
+ true ->
+ {:error,
+ "File #{filename} was not found in #{inspect([instance_path, frontend_path, priv_path])}"}
+ end
+ end
end