diff --git a/lib/chiya_web/indie/micropub_handler.ex b/lib/chiya_web/indie/micropub_handler.ex index 1905db7..1dbc83b 100644 --- a/lib/chiya_web/indie/micropub_handler.ex +++ b/lib/chiya_web/indie/micropub_handler.ex @@ -8,10 +8,11 @@ defmodule ChiyaWeb.Indie.MicropubHandler do @impl true def handle_create(type, properties, access_token) do dbg(properties) + dbg(type) with :ok <- Token.verify(access_token, "create", get_hostname()), {:ok, post_type} <- Props.get_post_type(properties), - {:ok, note_attrs} <- note_attrs(type, post_type, properties), + {:ok, note_attrs} <- get_attrs(type, post_type, properties), {:ok, note} <- Chiya.Notes.create_note(note_attrs) do {:ok, :created, Chiya.Notes.Note.note_url(note)} |> dbg() else @@ -58,16 +59,16 @@ defmodule ChiyaWeb.Indie.MicropubHandler do {:error, :insufficient_scope} end - defp note_attrs("h-entry", post_type, properties) do + defp get_attrs(type, post_type, properties) do + Logger.info("Creating a #{type}/#{post_type}..") + case post_type do - :note -> do_note_attrs(properties) + :note -> get_note_attrs(properties) _ -> {:error, :insufficient_scope} end end - defp note_attrs(_, _, _), do: {:error, :insufficient_scope} - - defp do_note_attrs(p) do + defp get_note_attrs(p) do content = Props.get_content(p) name = Props.get_title(p) || String.slice(content, 0..15) tags = Props.get_tags(p) |> Enum.join(",")