Update
This commit is contained in:
parent
cd1e5887c5
commit
f8bedff913
4 changed files with 61 additions and 25 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue