Update
This commit is contained in:
parent
188bc08494
commit
4af88f3e1d
44 changed files with 1041 additions and 34 deletions
38
lib/nulla_web/controllers/activitypub/note_controller.ex
Normal file
38
lib/nulla_web/controllers/activitypub/note_controller.ex
Normal file
|
@ -0,0 +1,38 @@
|
|||
defmodule NullaWeb.ActivityPub.NoteController do
|
||||
use NullaWeb, :controller
|
||||
alias Nulla.Repo
|
||||
alias NullaWeb.ActivityPub.NoteJSON
|
||||
alias Nulla.Notes
|
||||
|
||||
def show(conn, %{"username" => username, "id" => id}) do
|
||||
case Integer.parse(id) do
|
||||
{int_id, ""} ->
|
||||
note = Notes.get_note!(int_id) |> Repo.preload([:actor, :media_attachments])
|
||||
|
||||
cond do
|
||||
is_nil(note) ->
|
||||
conn
|
||||
|> put_status(:not_found)
|
||||
|> json(%{error: "Not Found"})
|
||||
|> halt()
|
||||
|
||||
username != note.actor.preferredUsername ->
|
||||
conn
|
||||
|> put_status(:not_found)
|
||||
|> json(%{error: "Not Found"})
|
||||
|> halt()
|
||||
|
||||
true ->
|
||||
conn
|
||||
|> put_resp_content_type("application/activity+json")
|
||||
|> json(NoteJSON.show(note))
|
||||
end
|
||||
|
||||
_ ->
|
||||
conn
|
||||
|> put_status(:not_found)
|
||||
|> json(%{error: "Not Found"})
|
||||
|> halt()
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue