From: FloatingGhost Date: Thu, 14 Jul 2022 10:17:14 +0000 (+0100) Subject: remove anonymous function from plug X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=d598c7a834cb3aa8d9d4ca4ce4c319d5829e6062;p=akkoma remove anonymous function from plug --- diff --git a/lib/pleroma/web/plugs/frontend_static.ex b/lib/pleroma/web/plugs/frontend_static.ex index 5d9ae2ff7..40f51e149 100644 --- a/lib/pleroma/web/plugs/frontend_static.ex +++ b/lib/pleroma/web/plugs/frontend_static.ex @@ -31,13 +31,13 @@ defmodule Pleroma.Web.Plugs.FrontendStatic 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 @@ defmodule Pleroma.Web.Plugs.FrontendStatic 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 diff --git a/lib/pleroma/web/swagger.ex b/lib/pleroma/web/swagger.ex index e75ce2180..0e32c468b 100644 --- a/lib/pleroma/web/swagger.ex +++ b/lib/pleroma/web/swagger.ex @@ -2,6 +2,6 @@ defmodule Pleroma.Web.Swagger do alias Pleroma.Config def ui_enabled? do - Config.get([:frontends, :swagger, "enabled"]) + Config.get([:frontends, :swagger, "enabled"], false) end end