1
0
mirror of https://github.com/mgerb/classic-wow-forums synced 2026-01-12 01:52:49 +00:00

server - adjust rate limiter - reply/thread mod update

This commit is contained in:
2018-01-25 19:57:36 -06:00
parent d6ec930370
commit 605e4ba94b
9 changed files with 121 additions and 23 deletions

View File

@@ -11,11 +11,21 @@ defmodule MyAppWeb.ThreadController do
|> Map.get("id")
# every 5 minutes user can submit new thread
{output, status} = case RateLimiter.limit(RateLimiter.new_thread_key, user_id, 300) do
{:ok, _} -> params
{output, status} = case RateLimiter.check_limit(RateLimiter.new_thread_key, user_id) do
{:ok, _} ->
{ok, data} = params
|> Map.put("user_id", user_id)
|> Data.Thread.insert
if ok == :ok do
# apply rate limiter only after submitting new post
RateLimiter.set_limit(RateLimiter.new_thread_key, user_id, 300)
end
{ok, data}
|> Response.put_resp
{:error, error} -> {error, 429}
end
@@ -71,4 +81,12 @@ defmodule MyAppWeb.ThreadController do
|> Response.json(output)
end
@spec mod_update(map, map) :: any
def mod_update(conn, params) do
{:ok, _} = Data.Thread.mod_update(params)
conn
|> put_status(200)
|> Response.json("ok")
end
end