clacks/lib/clacks_web/controllers/activities_controller.ex

45 lines
1.0 KiB
Elixir
Raw Normal View History

2019-10-06 23:41:18 +00:00
defmodule ClacksWeb.ActivitiesController do
use ClacksWeb, :controller
alias Clacks.{ActivityPub, Activity}
alias ClacksWeb.Router.Helpers, as: Routes
alias ClacksWeb.Endpoint
def get(conn, _params) do
ap_id = current_url(conn, %{})
case Activity.get_by_ap_id(ap_id) do
%Activity{local: true, id: id, data: data} ->
case conn.assigns[:format] do
"activity+json" ->
json(conn, data)
"html" ->
redirect(conn, to: Routes.frontend_path(Endpoint, :status, id))
end
_ ->
2020-04-23 02:54:46 +00:00
case conn.assigns[:format] do
"activity+json" ->
conn
|> put_status(404)
|> json(%{error: "Not Found"})
"html" ->
resp(conn, 404, "Not Found")
end
end
end
def get_status(conn, %{"id" => status_id}) do
case Activity.get(status_id) do
%Activity{local: true, data: data} ->
json(conn, data)
_ ->
conn
|> put_status(404)
|> json(%{error: "Not Found"})
2019-10-06 23:41:18 +00:00
end
end
end