This commit is contained in:
Mirai Kumiko 2025-06-19 17:21:52 +02:00
parent f963620cf0
commit 43ee272ca1
Signed by: miraikumiko
GPG key ID: 3F178B1B5E0CB278
3 changed files with 87 additions and 14 deletions

View file

@ -5,22 +5,40 @@ defmodule NullaWeb.NoteController do
alias Nulla.Models.Note
def show(conn, %{"username" => username, "id" => id}) do
accept = List.first(get_req_header(conn, "accept"))
note = Note.get_note(id) |> Repo.preload([:actor, :media_attachments])
case Integer.parse(id) do
{int_id, ""} ->
note = Note.get_note(int_id) |> Repo.preload([:actor, :media_attachments])
if username != note.actor.preferredUsername do
conn
|> put_status(:not_found)
|> json(%{error: "Not Found"})
|> halt()
end
cond do
is_nil(note) ->
conn
|> put_status(:not_found)
|> json(%{error: "Not Found"})
|> halt()
if accept in ["application/activity+json", "application/ld+json"] do
conn
|> put_resp_content_type("application/activity+json")
|> json(ActivityPub.note(note))
else
render(conn, :show, note: note, layout: false)
username != note.actor.preferredUsername ->
conn
|> put_status(:not_found)
|> json(%{error: "Not Found"})
|> halt()
true ->
accept = List.first(get_req_header(conn, "accept"))
if accept in ["application/activity+json", "application/ld+json"] do
conn
|> put_resp_content_type("application/activity+json")
|> json(ActivityPub.note(note))
else
render(conn, :show, note: note, layout: false)
end
end
_ ->
conn
|> put_status(:not_found)
|> json(%{error: "Not Found"})
|> halt()
end
end
end