clacks/lib/clacks_web/controllers/inbox_controller.ex

29 lines
678 B
Elixir
Raw Normal View History

2019-10-01 22:39:17 +00:00
defmodule ClacksWeb.InboxController do
2019-10-02 13:47:04 +00:00
require Logger
2019-10-01 22:39:17 +00:00
use ClacksWeb, :controller
2019-10-02 01:59:43 +00:00
alias Clacks.Inbox
2019-10-01 22:39:17 +00:00
plug Plug.Parsers, parsers: [:urlencoded, :json], json_decoder: Jason
plug ClacksWeb.Plug.HTTPSignature
2019-10-02 01:59:43 +00:00
def shared(conn, _params) do
handle(conn, conn.body_params)
2019-10-01 22:39:17 +00:00
end
2019-10-02 01:59:43 +00:00
def user_specific(conn, _params) do
handle(conn, conn.body_params)
2019-10-01 22:39:17 +00:00
end
2019-10-02 01:59:43 +00:00
2019-10-02 14:28:06 +00:00
def handle(conn, %{"type" => type} = activity) do
case Inbox.handle(activity) do
2019-10-02 13:49:59 +00:00
:ok ->
2019-10-02 14:28:06 +00:00
put_status(conn, 200)
2019-10-02 13:49:59 +00:00
{:error, reason} ->
2019-10-02 14:28:06 +00:00
Logger.error("Could not handle incoming #{type} activity: #{inspect(reason)}")
put_status(conn, 500)
2019-10-02 13:47:04 +00:00
end
|> json(%{})
2019-10-02 01:59:43 +00:00
end
2019-10-01 22:39:17 +00:00
end