more logging

This commit is contained in:
Inhji 2023-08-21 23:54:29 +02:00
parent 0012d8a5f7
commit e48242feb2
2 changed files with 24 additions and 14 deletions

View file

@ -22,18 +22,6 @@ defmodule ChiyaWeb.Indie.Micropub do
end
end
def find_note(note_url) do
slug = Chiya.Notes.Note.note_slug(note_url)
note = Chiya.Notes.get_note_by_slug_preloaded(slug)
if is_nil(note) do
Logger.error("Note with #{note_url} was not found.")
{:error, :invalid_request}
else
{:ok, note}
end
end
def update_note(note, replace, add, delete) do
with {:ok, note_attrs} <- get_update_attrs(replace, add, delete),
{:ok, note} <- Chiya.Notes.update_note(note, note_attrs) do
@ -48,6 +36,18 @@ defmodule ChiyaWeb.Indie.Micropub do
end
end
def find_note(note_url) do
slug = Chiya.Notes.Note.note_slug(note_url)
note = Chiya.Notes.get_note_by_slug_preloaded(slug)
if is_nil(note) do
Logger.error("Note with #{note_url} was not found.")
{:error, :invalid_request}
else
{:ok, note}
end
end
defp create_photos(note, properties) do
properties
|> Props.get_photos()

View file

@ -171,6 +171,7 @@ defmodule ChiyaWeb.Plugs.PlugMicropub do
Logger.info("Micropub: Handle create")
content_type = conn |> get_req_header("content-type") |> List.first()
Logger.info("Micropub: Content type #{content_type}")
handler = conn.private[:plug_micropub][:handler]
with {:ok, type, properties} <- parse_create_body(content_type, conn.body_params),
@ -189,6 +190,7 @@ defmodule ChiyaWeb.Plugs.PlugMicropub do
Logger.info("Micropub: Handle update")
content_type = conn |> get_req_header("content-type") |> List.first()
Logger.info("Micropub: Content type #{content_type}")
with "application/json" <- content_type,
{url, properties} when is_binary(url) <- Map.pop(conn.body_params, "url"),
@ -298,15 +300,23 @@ defmodule ChiyaWeb.Plugs.PlugMicropub do
Enum.all?(prop, &is_binary/1)
{_k, prop} when is_map(prop) ->
Logger.debug("Micropub: Parsing Add/Replace maps")
Enum.all?(prop, fn
{_k, v} when is_list(v) -> true
_ -> false
{_k, v} when is_list(v) ->
true
_ ->
Logger.warning("Micropub: Property value of #{prop} is not a list")
false
end)
_ ->
false
end)
Logger.info("Valid check successful: #{valid?}")
if valid? do
replace = Map.get(properties, "replace", %{})
add = Map.get(properties, "add", %{})