2019-09-29 01:57:11 +00:00
|
|
|
defmodule ClacksWeb.ObjectsController do
|
|
|
|
use ClacksWeb, :controller
|
2020-04-27 02:57:47 +00:00
|
|
|
alias Clacks.{Activity, Object}
|
2020-04-21 02:42:39 +00:00
|
|
|
alias ClacksWeb.Router.Helpers, as: Routes
|
|
|
|
alias ClacksWeb.Endpoint
|
2019-09-29 01:57:11 +00:00
|
|
|
|
2020-04-21 02:42:39 +00:00
|
|
|
def get(conn, params) do
|
|
|
|
case conn.assigns[:format] do
|
|
|
|
"activity+json" ->
|
|
|
|
get_object(conn, params)
|
|
|
|
|
|
|
|
"html" ->
|
|
|
|
redirect_to_status(conn, params)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
defp get_object(conn, _params) do
|
2019-09-29 01:57:11 +00:00
|
|
|
object_id = current_url(conn)
|
|
|
|
|
2020-04-21 02:42:39 +00:00
|
|
|
case Object.get_cached_by_ap_id(object_id) do
|
2019-09-29 01:57:11 +00:00
|
|
|
nil ->
|
|
|
|
conn
|
2020-04-21 02:42:39 +00:00
|
|
|
|> resp(404, "Not Found")
|
2019-09-29 01:57:11 +00:00
|
|
|
|
|
|
|
object ->
|
|
|
|
conn
|
|
|
|
|> put_resp_header("content-type", "application/activity+json")
|
|
|
|
|> json(object.data)
|
|
|
|
end
|
|
|
|
end
|
2020-04-21 02:42:39 +00:00
|
|
|
|
|
|
|
defp redirect_to_status(conn, _params) do
|
|
|
|
object_id = current_url(conn)
|
|
|
|
|
2021-08-26 13:59:55 +00:00
|
|
|
case Activity.get_by_object_ap_id(object_id, "Create") do
|
2020-04-21 02:42:39 +00:00
|
|
|
nil ->
|
|
|
|
conn
|
|
|
|
|> resp(404, "Not Found")
|
|
|
|
|
|
|
|
activity ->
|
|
|
|
redirect(conn, to: Routes.frontend_path(Endpoint, :status, activity.id))
|
|
|
|
end
|
|
|
|
end
|
2019-09-29 01:57:11 +00:00
|
|
|
end
|