Remove previous idempotency implementation from post_status
This commit is contained in:
parent
74132e3715
commit
0b8aeac0f3
1 changed files with 2 additions and 22 deletions
|
@ -561,18 +561,13 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
|
||||||
else
|
else
|
||||||
params = Map.drop(params, ["scheduled_at"])
|
params = Map.drop(params, ["scheduled_at"])
|
||||||
|
|
||||||
case get_cached_status_or_post(conn, params) do
|
case CommonAPI.post(user, params) do
|
||||||
{:ignore, message} ->
|
|
||||||
conn
|
|
||||||
|> put_status(422)
|
|
||||||
|> json(%{error: message})
|
|
||||||
|
|
||||||
{:error, message} ->
|
{:error, message} ->
|
||||||
conn
|
conn
|
||||||
|> put_status(422)
|
|> put_status(422)
|
||||||
|> json(%{error: message})
|
|> json(%{error: message})
|
||||||
|
|
||||||
{_, activity} ->
|
{:ok, activity} ->
|
||||||
conn
|
conn
|
||||||
|> put_view(StatusView)
|
|> put_view(StatusView)
|
||||||
|> try_render("status.json", %{activity: activity, for: user, as: :activity})
|
|> try_render("status.json", %{activity: activity, for: user, as: :activity})
|
||||||
|
@ -580,21 +575,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp get_cached_status_or_post(%{assigns: %{user: user}} = conn, params) do
|
|
||||||
idempotency_key =
|
|
||||||
case get_req_header(conn, "idempotency-key") do
|
|
||||||
[key] -> key
|
|
||||||
_ -> Ecto.UUID.generate()
|
|
||||||
end
|
|
||||||
|
|
||||||
Cachex.fetch(:idempotency_cache, idempotency_key, fn _ ->
|
|
||||||
case CommonAPI.post(user, params) do
|
|
||||||
{:ok, activity} -> activity
|
|
||||||
{:error, message} -> {:ignore, message}
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
def delete_status(%{assigns: %{user: user}} = conn, %{"id" => id}) do
|
def delete_status(%{assigns: %{user: user}} = conn, %{"id" => id}) do
|
||||||
with {:ok, %Activity{}} <- CommonAPI.delete(id, user) do
|
with {:ok, %Activity{}} <- CommonAPI.delete(id, user) do
|
||||||
json(conn, %{})
|
json(conn, %{})
|
||||||
|
|
Loading…
Reference in a new issue