Merge branch 'develop' into void-fix
This commit is contained in:
commit
64716b4833
4 changed files with 14 additions and 10 deletions
|
@ -1,7 +0,0 @@
|
|||
defmodule Akkoma.Web.Swagger do
|
||||
alias Pleroma.Config
|
||||
|
||||
def ui_enabled? do
|
||||
Config.get([:frontends, :swagger, "enabled"])
|
||||
end
|
||||
end
|
|
@ -72,7 +72,7 @@ defmodule Pleroma.Web.Endpoint do
|
|||
at: "/akkoma/swaggerui",
|
||||
frontend_type: :swagger,
|
||||
gzip: true,
|
||||
if: &Akkoma.Web.Swagger.ui_enabled?/0,
|
||||
if: &Pleroma.Web.Swagger.ui_enabled?/0,
|
||||
cache_control_for_etags: @static_cache_control,
|
||||
headers: %{
|
||||
"cache-control" => @static_cache_control
|
||||
|
|
|
@ -31,13 +31,13 @@ def init(opts) do
|
|||
|> Keyword.put(:from, "__unconfigured_frontend_static_plug")
|
||||
|> Plug.Static.init()
|
||||
|> 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
|
||||
|
||||
def call(conn, opts) do
|
||||
with false <- api_route?(conn.path_info),
|
||||
false <- invalid_path?(conn.path_info),
|
||||
true <- opts[:if].(),
|
||||
true <- enabled?(opts[:if]),
|
||||
frontend_type <- Map.get(opts, :frontend_type, :primary),
|
||||
path when not is_nil(path) <- file_path("", frontend_type) do
|
||||
call_static(conn, opts, path)
|
||||
|
@ -47,6 +47,10 @@ def call(conn, opts) do
|
|||
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
|
||||
invalid_path?(list, :binary.compile_pattern(["/", "\\", ":", "\0"]))
|
||||
end
|
||||
|
|
7
lib/pleroma/web/swagger.ex
Normal file
7
lib/pleroma/web/swagger.ex
Normal file
|
@ -0,0 +1,7 @@
|
|||
defmodule Pleroma.Web.Swagger do
|
||||
alias Pleroma.Config
|
||||
|
||||
def ui_enabled? do
|
||||
Config.get([:frontends, :swagger, "enabled"], false)
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue