Attempt to filter out API calls from FrontendStatic plug
This commit is contained in:
parent
6b6791f911
commit
cea31df6a6
2 changed files with 23 additions and 2 deletions
|
|
@ -10,6 +10,8 @@ defmodule Pleroma.Web.Plugs.FrontendStatic do
|
|||
"""
|
||||
@behaviour Plug
|
||||
|
||||
@api_routes Pleroma.Web.get_api_routes()
|
||||
|
||||
def file_path(path, frontend_type \\ :primary) do
|
||||
if configuration = Pleroma.Config.get([:frontends, frontend_type]) do
|
||||
instance_static_path = Pleroma.Config.get([:instance, :static_dir], "instance/static")
|
||||
|
|
@ -34,7 +36,8 @@ defmodule Pleroma.Web.Plugs.FrontendStatic do
|
|||
end
|
||||
|
||||
def call(conn, opts) do
|
||||
with false <- invalid_path?(conn.path_info),
|
||||
with false <- api_route?(conn.path_info),
|
||||
false <- invalid_path?(conn.path_info),
|
||||
frontend_type <- Map.get(opts, :frontend_type, :primary),
|
||||
path when not is_nil(path) <- file_path("", frontend_type) do
|
||||
call_static(conn, opts, path)
|
||||
|
|
@ -52,6 +55,12 @@ defmodule Pleroma.Web.Plugs.FrontendStatic do
|
|||
defp invalid_path?([h | t], match), do: String.contains?(h, match) or invalid_path?(t)
|
||||
defp invalid_path?([], _match), do: false
|
||||
|
||||
defp api_route?(list) when is_list(list) and length(list) > 0 do
|
||||
List.first(list) in @api_routes
|
||||
end
|
||||
|
||||
defp api_route?(_), do: false
|
||||
|
||||
defp call_static(conn, opts, from) do
|
||||
opts = Map.put(opts, :from, from)
|
||||
Plug.Static.call(conn, opts)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue