devel #90
1 changed files with 7 additions and 6 deletions
|
@ -8,10 +8,11 @@ defmodule ChiyaWeb.Indie.MicropubHandler do
|
||||||
@impl true
|
@impl true
|
||||||
def handle_create(type, properties, access_token) do
|
def handle_create(type, properties, access_token) do
|
||||||
dbg(properties)
|
dbg(properties)
|
||||||
|
dbg(type)
|
||||||
|
|
||||||
with :ok <- Token.verify(access_token, "create", get_hostname()),
|
with :ok <- Token.verify(access_token, "create", get_hostname()),
|
||||||
{:ok, post_type} <- Props.get_post_type(properties),
|
{: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, note} <- Chiya.Notes.create_note(note_attrs) do
|
||||||
{:ok, :created, Chiya.Notes.Note.note_url(note)} |> dbg()
|
{:ok, :created, Chiya.Notes.Note.note_url(note)} |> dbg()
|
||||||
else
|
else
|
||||||
|
@ -58,16 +59,16 @@ defmodule ChiyaWeb.Indie.MicropubHandler do
|
||||||
{:error, :insufficient_scope}
|
{:error, :insufficient_scope}
|
||||||
end
|
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
|
case post_type do
|
||||||
:note -> do_note_attrs(properties)
|
:note -> get_note_attrs(properties)
|
||||||
_ -> {:error, :insufficient_scope}
|
_ -> {:error, :insufficient_scope}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp note_attrs(_, _, _), do: {:error, :insufficient_scope}
|
defp get_note_attrs(p) do
|
||||||
|
|
||||||
defp do_note_attrs(p) do
|
|
||||||
content = Props.get_content(p)
|
content = Props.get_content(p)
|
||||||
name = Props.get_title(p) || String.slice(content, 0..15)
|
name = Props.get_title(p) || String.slice(content, 0..15)
|
||||||
tags = Props.get_tags(p) |> Enum.join(",")
|
tags = Props.get_tags(p) |> Enum.join(",")
|
||||||
|
|
Loading…
Reference in a new issue