projects
/
akkoma
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'issue/2036-part-2' into 'develop'
[akkoma]
/
lib
/
pleroma
/
plugs
/
instance_static.ex
diff --git
a/lib/pleroma/plugs/instance_static.ex
b/lib/pleroma/plugs/instance_static.ex
index af2f6f331bb0e478f50d699ee9e24ca2e575e841..0fb57e42257f5927cd6c7e6299782d8526ff9c4f 100644
(file)
--- a/
lib/pleroma/plugs/instance_static.ex
+++ b/
lib/pleroma/plugs/instance_static.ex
@@
-1,8
+1,10
@@
# Pleroma: A lightweight social networking server
# Pleroma: A lightweight social networking server
-# Copyright © 2017-20
19
Pleroma Authors <https://pleroma.social/>
+# Copyright © 2017-20
20
Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Plugs.InstanceStatic do
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Plugs.InstanceStatic do
+ require Pleroma.Constants
+
@moduledoc """
This is a shim to call `Plug.Static` but with runtime `from` configuration.
@moduledoc """
This is a shim to call `Plug.Static` but with runtime `from` configuration.
@@
-14,30
+16,24
@@
defmodule Pleroma.Plugs.InstanceStatic do
instance_path =
Path.join(Pleroma.Config.get([:instance, :static_dir], "instance/static/"), path)
instance_path =
Path.join(Pleroma.Config.get([:instance, :static_dir], "instance/static/"), path)
- if File.exists?(instance_path) do
- instance_path
- else
+ frontend_path = Pleroma.Plugs.FrontendStatic.file_path(path, :primary)
+
+ (File.exists?(instance_path) && instance_path) ||
+ (frontend_path && File.exists?(frontend_path) && frontend_path) ||
Path.join(Application.app_dir(:pleroma, "priv/static/"), path)
Path.join(Application.app_dir(:pleroma, "priv/static/"), path)
- end
end
end
- @only ~w(index.html static emoji packs sounds images instance favicon.png)
-
def init(opts) do
opts
|> Keyword.put(:from, "__unconfigured_instance_static_plug")
def init(opts) do
opts
|> Keyword.put(:from, "__unconfigured_instance_static_plug")
- |> Keyword.put(:at, "/__unconfigured_instance_static_plug")
|> Plug.Static.init()
end
|> Plug.Static.init()
end
- for only <- @only do
- at = Plug.Router.Utils.split("/")
-
- def call(conn = %{request_path: "/" <> unquote(only) <> _}, opts) do
+ for only <- Pleroma.Constants.static_only_files() do
+ def call(%{request_path: "/" <> unquote(only) <> _} = conn, opts) do
call_static(
conn,
opts,
call_static(
conn,
opts,
- unquote(at),
Pleroma.Config.get([:instance, :static_dir], "instance/static")
)
end
Pleroma.Config.get([:instance, :static_dir], "instance/static")
)
end
@@
-47,11
+43,10
@@
defmodule Pleroma.Plugs.InstanceStatic do
conn
end
conn
end
- defp call_static(conn, opts,
at,
from) do
+ defp call_static(conn, opts, from) do
opts =
opts
|> Map.put(:from, from)
opts =
opts
|> Map.put(:from, from)
- |> Map.put(:at, at)
Plug.Static.call(conn, opts)
end
Plug.Static.call(conn, opts)
end