Merge pull request 'devel' (#269) from devel into main

Reviewed-on: #269
This commit is contained in:
inhji 2023-08-21 23:55:14 +02:00
commit 8ee52c33c5
3 changed files with 26 additions and 17 deletions

View file

@ -14,9 +14,8 @@ config :chiya, ChiyaWeb.Endpoint, cache_static_manifest: "priv/static/cache_mani
# Configures Swoosh API Client
config :swoosh, api_client: Swoosh.ApiClient.Finch, finch_name: Chiya.Finch
# Do not print debug messages in production
# config :logger, level: :debug
config :logger, :default_handler, level: :info
# Do print debug messages in production
config :logger, :default_handler, level: :debug
config :cors_plug,
origin: ["app://obsidian.md"],

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", %{})