Modify limit_plug for use by API (#15)

This commit is contained in:
SomewhatDamaged 2020-08-23 02:11:50 +10:00 committed by GitHub
parent a5c53894d6
commit dec3615da5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -51,6 +51,12 @@ defmodule PhilomenaWeb.LimitPlug do
|> Conn.send_resp(:multiple_choices, "")
|> Conn.halt()
api?(conn) ->
conn
|> Conn.put_status(:too_many_requests)
|> Controller.text("")
|> Conn.halt()
true ->
conn
|> Controller.put_flash(:error, error)
@ -67,6 +73,13 @@ defmodule PhilomenaWeb.LimitPlug do
defp current_user_id(%{id: id}), do: id
defp current_user_id(_), do: nil
defp api?(conn) do
case conn.path_info do
["api" | _] -> true
_ -> false
end
end
defp ajax?(conn) do
case Conn.get_req_header(conn, "x-requested-with") do
[value] -> String.downcase(value) == "xmlhttprequest"