devel #269
2 changed files with 24 additions and 14 deletions
|
@ -22,18 +22,6 @@ defmodule ChiyaWeb.Indie.Micropub do
|
||||||
end
|
end
|
||||||
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
|
def update_note(note, replace, add, delete) do
|
||||||
with {:ok, note_attrs} <- get_update_attrs(replace, add, delete),
|
with {:ok, note_attrs} <- get_update_attrs(replace, add, delete),
|
||||||
{:ok, note} <- Chiya.Notes.update_note(note, note_attrs) do
|
{:ok, note} <- Chiya.Notes.update_note(note, note_attrs) do
|
||||||
|
@ -48,6 +36,18 @@ defmodule ChiyaWeb.Indie.Micropub do
|
||||||
end
|
end
|
||||||
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
|
defp create_photos(note, properties) do
|
||||||
properties
|
properties
|
||||||
|> Props.get_photos()
|
|> Props.get_photos()
|
||||||
|
|
|
@ -171,6 +171,7 @@ defmodule ChiyaWeb.Plugs.PlugMicropub do
|
||||||
Logger.info("Micropub: Handle create")
|
Logger.info("Micropub: Handle create")
|
||||||
|
|
||||||
content_type = conn |> get_req_header("content-type") |> List.first()
|
content_type = conn |> get_req_header("content-type") |> List.first()
|
||||||
|
Logger.info("Micropub: Content type #{content_type}")
|
||||||
handler = conn.private[:plug_micropub][:handler]
|
handler = conn.private[:plug_micropub][:handler]
|
||||||
|
|
||||||
with {:ok, type, properties} <- parse_create_body(content_type, conn.body_params),
|
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")
|
Logger.info("Micropub: Handle update")
|
||||||
|
|
||||||
content_type = conn |> get_req_header("content-type") |> List.first()
|
content_type = conn |> get_req_header("content-type") |> List.first()
|
||||||
|
Logger.info("Micropub: Content type #{content_type}")
|
||||||
|
|
||||||
with "application/json" <- content_type,
|
with "application/json" <- content_type,
|
||||||
{url, properties} when is_binary(url) <- Map.pop(conn.body_params, "url"),
|
{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)
|
Enum.all?(prop, &is_binary/1)
|
||||||
|
|
||||||
{_k, prop} when is_map(prop) ->
|
{_k, prop} when is_map(prop) ->
|
||||||
|
Logger.debug("Micropub: Parsing Add/Replace maps")
|
||||||
|
|
||||||
Enum.all?(prop, fn
|
Enum.all?(prop, fn
|
||||||
{_k, v} when is_list(v) -> true
|
{_k, v} when is_list(v) ->
|
||||||
_ -> false
|
true
|
||||||
|
|
||||||
|
_ ->
|
||||||
|
Logger.warning("Micropub: Property value of #{prop} is not a list")
|
||||||
|
false
|
||||||
end)
|
end)
|
||||||
|
|
||||||
_ ->
|
_ ->
|
||||||
false
|
false
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
Logger.info("Valid check successful: #{valid?}")
|
||||||
|
|
||||||
if valid? do
|
if valid? do
|
||||||
replace = Map.get(properties, "replace", %{})
|
replace = Map.get(properties, "replace", %{})
|
||||||
add = Map.get(properties, "add", %{})
|
add = Map.get(properties, "add", %{})
|
||||||
|
|
Loading…
Reference in a new issue