mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-12-05 00:57:59 +01:00
28 lines
610 B
Elixir
28 lines
610 B
Elixir
defmodule PhilomenaWeb.ScraperCachePlug do
|
|
@spec init(any()) :: any()
|
|
def init(opts) do
|
|
opts
|
|
end
|
|
|
|
@spec call(Plug.Conn.t(), any()) :: Plug.Conn.t()
|
|
def call(conn, _opts) do
|
|
params =
|
|
conn.params
|
|
|> Map.put_new("image", %{})
|
|
|> Map.put_new("scraper_cache", conn.params["url"])
|
|
|> Map.put("distance", normalize_dist(conn.params))
|
|
|
|
%Plug.Conn{conn | params: params}
|
|
end
|
|
|
|
defp normalize_dist(%{"distance" => distance}) do
|
|
("0" <> distance)
|
|
|> Float.parse()
|
|
|> elem(0)
|
|
|> Float.to_string()
|
|
end
|
|
|
|
defp normalize_dist(_dist) do
|
|
"0.25"
|
|
end
|
|
end
|