Change structure
This commit is contained in:
parent
01c2c57933
commit
ddfb58c041
16 changed files with 153 additions and 66 deletions
44
lib/nulla_web/controllers/web/note_controller.ex
Normal file
44
lib/nulla_web/controllers/web/note_controller.ex
Normal file
|
@ -0,0 +1,44 @@
|
|||
defmodule NullaWeb.Web.NoteController do
|
||||
use NullaWeb, :controller
|
||||
alias Nulla.Repo
|
||||
alias Nulla.ActivityPub
|
||||
alias Nulla.Models.Note
|
||||
|
||||
def show(conn, %{"username" => username, "id" => id}) do
|
||||
case Integer.parse(id) do
|
||||
{int_id, ""} ->
|
||||
note = Note.get_note(id: 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 ->
|
||||
format = Phoenix.Controller.get_format(conn)
|
||||
|
||||
if format == "activity+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
|
Loading…
Add table
Add a link
Reference in a new issue