mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 13:47:58 +01:00
Modify limit_plug for use by API (#15)
This commit is contained in:
parent
a5c53894d6
commit
dec3615da5
1 changed files with 13 additions and 0 deletions
|
@ -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"
|
||||
|
|
Loading…
Reference in a new issue