aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/mix/tasks/pleroma/frontend.ex40
-rw-r--r--lib/pleroma/plugs/instance_static.ex38
2 files changed, 52 insertions, 26 deletions
diff --git a/lib/mix/tasks/pleroma/frontend.ex b/lib/mix/tasks/pleroma/frontend.ex
index 7a691b95d..0d52ae69e 100644
--- a/lib/mix/tasks/pleroma/frontend.ex
+++ b/lib/mix/tasks/pleroma/frontend.ex
@@ -4,7 +4,7 @@
defmodule Mix.Tasks.Pleroma.Frontend do
use Mix.Task
- alias __MODULE__.Fetcher
+ import Mix.Pleroma
@shortdoc "Manages the Pleroma frontends"
@moduledoc File.read!("docs/administration/CLI_tasks/frontend.md")
@@ -15,21 +15,36 @@ defmodule Mix.Tasks.Pleroma.Frontend do
rest,
strict: [
reference: :string
- ]
+ ],
+ aliases: [r: :reference]
)
reference = options[:reference] || "master"
- IO.puts("Downloading reference #{reference}")
+ shell_info("Downloading reference #{reference}")
url =
"https://git.pleroma.social/pleroma/pleroma-fe/-/jobs/artifacts/#{reference}/download?job=build"
- sd = Pleroma.Config.get([:instance, :static_dir]) |> Path.expand()
+ sd =
+ Pleroma.Config.get([:instance, :frontends_dir], "instance/frontends")
+ |> Path.join("pleroma-fe")
+ |> Path.expand()
- with {_, {:ok, %{status: 200, body: body}}} <- {:fetch, Fetcher.get(url)},
- {_, {:ok, results}} <- {:unzip, :zip.unzip(body, [:memory])} do
- IO.puts("Writing to #{sd}")
+ adapter =
+ if Pleroma.Config.get(:env) == :test do
+ Tesla.Mock
+ else
+ Tesla.Adapter.Httpc
+ end
+
+ client = Tesla.client([Tesla.Middleware.FollowRedirects], adapter)
+
+ with {_, {:ok, %{status: 200, body: body}}} <- {:fetch, Tesla.get(client, url)},
+ {_, {:ok, results}} <- {:unzip, :zip.unzip(body, [:memory])},
+ shell_info("Cleaning #{sd}"),
+ {_, {:ok, _}} <- {:clean_up, File.rm_rf(sd)} do
+ shell_info("Writing to #{sd}")
results
|> Enum.each(fn {path, contents} ->
@@ -39,16 +54,9 @@ defmodule Mix.Tasks.Pleroma.Frontend do
File.write!(path, contents)
end)
- IO.puts("Successfully downloaded and unpacked the frontend")
+ shell_info("Successfully downloaded and unpacked the frontend")
else
- {error, _} -> IO.puts("Step failed: #{error}")
+ {error, _} -> shell_error("Step failed: #{error}")
end
end
end
-
-defmodule Mix.Tasks.Pleroma.Frontend.Fetcher do
- use Tesla
- plug(Tesla.Middleware.FollowRedirects)
-
- adapter(Tesla.Adapter.Httpc)
-end
diff --git a/lib/pleroma/plugs/instance_static.ex b/lib/pleroma/plugs/instance_static.ex
index 927fa2663..f7c9df5f9 100644
--- a/lib/pleroma/plugs/instance_static.ex
+++ b/lib/pleroma/plugs/instance_static.ex
@@ -10,19 +10,25 @@ defmodule Pleroma.Plugs.InstanceStatic do
"""
@behaviour Plug
+ alias Pleroma.Config
+
def file_path(path) do
- instance_path =
- Path.join(Pleroma.Config.get([:instance, :static_dir], "instance/static/"), path)
+ instance_path = Path.join(Config.get([:instance, :static_dir], "instance/static/"), path)
+
+ frontends_path =
+ Config.get([:instance, :frontends_dir], "instance/frontends/")
+ |> Path.join("pleroma-fe")
+ |> Path.join(path)
- if File.exists?(instance_path) do
- instance_path
- else
- Path.join(Application.app_dir(:pleroma, "priv/static/"), path)
+ cond do
+ File.exists?(instance_path) -> instance_path
+ File.exists?(frontends_path) -> frontends_path
+ true -> Path.join(Application.app_dir(:pleroma, "priv/static/"), path)
end
end
@only ~w(index.html robots.txt static emoji packs sounds images instance favicon.png sw.js
- sw-pleroma.js)
+ sw-pleroma.js fontello)
def init(opts) do
opts
@@ -38,8 +44,7 @@ defmodule Pleroma.Plugs.InstanceStatic do
call_static(
conn,
opts,
- unquote(at),
- Pleroma.Config.get([:instance, :static_dir], "instance/static")
+ unquote(at)
)
end
end
@@ -48,7 +53,20 @@ defmodule Pleroma.Plugs.InstanceStatic do
conn
end
- defp call_static(conn, opts, at, from) do
+ defp call_static(conn, opts, at) do
+ static_dir = Config.get([:instance, :static_dir], "instance/static/")
+
+ frontend_dir =
+ Config.get([:instance, :frontends_dir], "instance/frontends/")
+ |> Path.join("pleroma-fe")
+
+ from =
+ if File.exists?(Path.join(static_dir, conn.request_path)) do
+ static_dir
+ else
+ frontend_dir
+ end
+
opts =
opts
|> Map.put(:from, from)