34 lines
941 B
Elixir
34 lines
941 B
Elixir
|
defmodule TuskerPushWeb.PushController do
|
||
|
use TuskerPushWeb, :controller
|
||
|
|
||
|
require Logger
|
||
|
|
||
|
def push(conn, %{"id" => id}) do
|
||
|
with {:registration, registration} when not is_nil(registration) <-
|
||
|
{:registration, TuskerPush.get_registration(id)},
|
||
|
:ok <- TuskerPush.check_registration_expired(registration),
|
||
|
{:ok, body, conn} <- read_body(conn) do
|
||
|
IO.inspect(body |> byte_size())
|
||
|
send_resp(conn, 200, "ok")
|
||
|
else
|
||
|
{:registration, nil} ->
|
||
|
send_resp(conn, 400, "unregistered")
|
||
|
|
||
|
{:expired, registration} ->
|
||
|
TuskerPush.unregister(registration)
|
||
|
|
||
|
send_resp(conn, 400, "unregistered")
|
||
|
|
||
|
{:more, _, conn} ->
|
||
|
Logger.error("Didn't finish reading")
|
||
|
|
||
|
send_resp(conn, 500, "failed to read body")
|
||
|
|
||
|
{:error, reason} ->
|
||
|
Logger.error("Reading body: #{inspect(reason)}")
|
||
|
|
||
|
send_resp(conn, 500, "failed to read body")
|
||
|
end
|
||
|
end
|
||
|
end
|