fix missing micropub_channel
This commit is contained in:
parent
60e814d15e
commit
42565be50c
2 changed files with 13 additions and 13 deletions
|
@ -4,9 +4,12 @@ defmodule ChiyaWeb.Indie.Micropub do
|
||||||
alias ChiyaWeb.Indie.Properties, as: Props
|
alias ChiyaWeb.Indie.Properties, as: Props
|
||||||
alias ChiyaWeb.Indie.Token
|
alias ChiyaWeb.Indie.Token
|
||||||
|
|
||||||
def create_note(type, properties, channel_id) do
|
def create_note(type, properties) do
|
||||||
|
settings = Chiya.Site.get_settings()
|
||||||
|
|
||||||
with {:ok, post_type} <- Props.get_post_type(properties),
|
with {:ok, post_type} <- Props.get_post_type(properties),
|
||||||
{:ok, note_attrs} <- get_attrs(type, post_type, properties, channel_id),
|
{:ok, note_attrs} <-
|
||||||
|
get_attrs(type, post_type, properties, settings.micropub_channel_id),
|
||||||
{:ok, note} <- Chiya.Notes.create_note(note_attrs) do
|
{:ok, note} <- Chiya.Notes.create_note(note_attrs) do
|
||||||
Logger.info("Note created!")
|
Logger.info("Note created!")
|
||||||
|
|
||||||
|
@ -50,12 +53,12 @@ defmodule ChiyaWeb.Indie.Micropub do
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp get_attrs(type, post_type, properties, default_channel_id) do
|
defp get_attrs(type, post_type, properties, channel_id) do
|
||||||
Logger.info("Creating a #{type}/#{post_type}..")
|
Logger.info("Creating a #{type}/#{post_type}..")
|
||||||
|
|
||||||
channel =
|
channel =
|
||||||
if default_channel_id,
|
if channel_id,
|
||||||
do: Chiya.Channels.get_channel(default_channel_id),
|
do: Chiya.Channels.get_channel(channel_id),
|
||||||
else: nil
|
else: nil
|
||||||
|
|
||||||
case post_type do
|
case post_type do
|
||||||
|
@ -87,7 +90,7 @@ defmodule ChiyaWeb.Indie.Micropub do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp get_note_attrs(p, default_channel) do
|
defp get_note_attrs(p, channel) do
|
||||||
content = Props.get_content(p)
|
content = Props.get_content(p)
|
||||||
name = Props.get_title(p) || Chiya.Notes.Note.note_title(content)
|
name = Props.get_title(p) || Chiya.Notes.Note.note_title(content)
|
||||||
tags = Props.get_tags(p) |> Enum.join(",")
|
tags = Props.get_tags(p) |> Enum.join(",")
|
||||||
|
@ -105,8 +108,8 @@ defmodule ChiyaWeb.Indie.Micropub do
|
||||||
}
|
}
|
||||||
|
|
||||||
attrs =
|
attrs =
|
||||||
if default_channel,
|
if channel,
|
||||||
do: Map.put(attrs, :channel, default_channel),
|
do: Map.put(attrs, :channels, [channel]),
|
||||||
else: attrs
|
else: attrs
|
||||||
|
|
||||||
{:ok, attrs}
|
{:ok, attrs}
|
||||||
|
|
|
@ -23,11 +23,8 @@ defmodule ChiyaWeb.Indie.MicropubHandler do
|
||||||
Logger.info("Properties: #{inspect(properties)}")
|
Logger.info("Properties: #{inspect(properties)}")
|
||||||
Logger.info("Type: #{type}")
|
Logger.info("Type: #{type}")
|
||||||
|
|
||||||
settings = Chiya.Site.get_settings()
|
|
||||||
channel_id = settings.micropub_channel_id
|
|
||||||
|
|
||||||
case Micropub.verify_token(access_token) do
|
case Micropub.verify_token(access_token) do
|
||||||
:ok -> Micropub.create_note(type, properties, channel_id)
|
:ok -> Micropub.create_note(type, properties)
|
||||||
_ -> {:error, :invalid_request}
|
_ -> {:error, :invalid_request}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue