nulla/lib/nulla_web/controllers/note_controller.ex
2025-06-19 07:39:11 +02:00

26 lines
741 B
Elixir

defmodule NullaWeb.NoteController do
use NullaWeb, :controller
alias Nulla.Repo
alias Nulla.ActivityPub
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([:user, :media_attachments])
if username != note.user.username do
conn
|> put_status(:not_found)
|> json(%{error: "Note not found"})
|> halt()
end
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
end