Merge pull request 'remove anonymous function from plug' (#70) from remove-anon-function into develop
Reviewed-on: https://akkoma.dev/AkkomaGang/akkoma/pulls/70
This commit is contained in:
commit
7ecc10b097
|
@ -31,13 +31,13 @@ def init(opts) do
|
||||||
|> Keyword.put(:from, "__unconfigured_frontend_static_plug")
|
|> Keyword.put(:from, "__unconfigured_frontend_static_plug")
|
||||||
|> Plug.Static.init()
|
|> Plug.Static.init()
|
||||||
|> Map.put(:frontend_type, opts[:frontend_type])
|
|> Map.put(:frontend_type, opts[:frontend_type])
|
||||||
|> Map.put(:if, Keyword.get(opts, :if, fn -> true end))
|
|> Map.put(:if, Keyword.get(opts, :if, true))
|
||||||
end
|
end
|
||||||
|
|
||||||
def call(conn, opts) do
|
def call(conn, opts) do
|
||||||
with false <- api_route?(conn.path_info),
|
with false <- api_route?(conn.path_info),
|
||||||
false <- invalid_path?(conn.path_info),
|
false <- invalid_path?(conn.path_info),
|
||||||
true <- opts[:if].(),
|
true <- enabled?(opts[:if]),
|
||||||
frontend_type <- Map.get(opts, :frontend_type, :primary),
|
frontend_type <- Map.get(opts, :frontend_type, :primary),
|
||||||
path when not is_nil(path) <- file_path("", frontend_type) do
|
path when not is_nil(path) <- file_path("", frontend_type) do
|
||||||
call_static(conn, opts, path)
|
call_static(conn, opts, path)
|
||||||
|
@ -47,6 +47,10 @@ def call(conn, opts) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp enabled?(if_opt) when is_function(if_opt), do: if_opt.()
|
||||||
|
defp enabled?(true), do: true
|
||||||
|
defp enabled?(_), do: false
|
||||||
|
|
||||||
defp invalid_path?(list) do
|
defp invalid_path?(list) do
|
||||||
invalid_path?(list, :binary.compile_pattern(["/", "\\", ":", "\0"]))
|
invalid_path?(list, :binary.compile_pattern(["/", "\\", ":", "\0"]))
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,6 +2,6 @@ defmodule Pleroma.Web.Swagger do
|
||||||
alias Pleroma.Config
|
alias Pleroma.Config
|
||||||
|
|
||||||
def ui_enabled? do
|
def ui_enabled? do
|
||||||
Config.get([:frontends, :swagger, "enabled"])
|
Config.get([:frontends, :swagger, "enabled"], false)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue