This commit is contained in:
Mirai Kumiko 2025-06-08 13:44:23 +02:00
parent cd1e5887c5
commit f8bedff913
Signed by: miraikumiko
GPG key ID: 3F178B1B5E0CB278
4 changed files with 61 additions and 25 deletions

View file

@ -1,8 +1,9 @@
defmodule NullaWeb.NoteController do
use NullaWeb, :controller
alias Nulla.Notes
alias Nulla.Repo
alias Nulla.Models.Note
alias Nulla.Models.InstanceSettings
alias Nulla.ActivityPub
def index(conn, _params) do
notes = Notes.list_notes()
@ -26,11 +27,33 @@ defmodule NullaWeb.NoteController do
end
end
def show(conn, %{"id" => id}) do
note = Notes.get_note!(id)
render(conn, :show, note: note)
def show(conn, %{"username" => username, "note_id" => note_id}) do
accept = List.first(get_req_header(conn, "accept"))
instance_settings = InstanceSettings.get_instance_settings!()
domain = instance_settings.domain
note = Note.get_note!(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(domain, note))
else
render(conn, :show, domain: domain, note: note, layout: false)
end
end
#def show(conn, %{"id" => id}) do
# note = Notes.get_note!(id)
# render(conn, :show, note: note)
#end
def edit(conn, %{"id" => id}) do
note = Notes.get_note!(id)
changeset = Notes.change_note(note)

View file

@ -22,7 +22,7 @@ defmodule NullaWeb.Router do
pipe_through :browser
get "/@:username", UserController, :show
resources "/users", UserController
get "/@:username/:note_id", NoteController, :show
end
# Other scopes may use custom stacks.