first pass of channel support for micropub
This commit is contained in:
parent
c6bf356b84
commit
3bcef1ad8a
2 changed files with 20 additions and 12 deletions
|
@ -53,6 +53,8 @@ defmodule Chiya.Channels do
|
||||||
"""
|
"""
|
||||||
def get_channel!(id), do: Repo.get!(Channel, id)
|
def get_channel!(id), do: Repo.get!(Channel, id)
|
||||||
|
|
||||||
|
def get_channel(id), do: Repo.get(Channel, id)
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Gets a single channel with all associated entities preloaded.
|
Gets a single channel with all associated entities preloaded.
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -21,11 +21,11 @@ defmodule ChiyaWeb.Indie.MicropubHandler do
|
||||||
Logger.info("Type: #{type}")
|
Logger.info("Type: #{type}")
|
||||||
|
|
||||||
settings = Chiya.Site.get_settings()
|
settings = Chiya.Site.get_settings()
|
||||||
micropub_channel = settings.micropub_channel_id
|
micropub_channel_id = settings.micropub_channel_id
|
||||||
|
|
||||||
with :ok <- verify_token(access_token),
|
with :ok <- verify_token(access_token),
|
||||||
{:ok, post_type} <- Props.get_post_type(properties),
|
{:ok, post_type} <- Props.get_post_type(properties),
|
||||||
{:ok, note_attrs} <- get_attrs(type, post_type, properties, micropub_channel),
|
{:ok, note_attrs} <- get_attrs(type, post_type, properties, 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!")
|
||||||
{:ok, :created, Chiya.Notes.Note.note_url(note)}
|
{:ok, :created, Chiya.Notes.Note.note_url(note)}
|
||||||
|
@ -160,11 +160,13 @@ defmodule ChiyaWeb.Indie.MicropubHandler do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp get_attrs(type, post_type, properties, default_channel) do
|
defp get_attrs(type, post_type, properties, default_channel_id) do
|
||||||
Logger.info("Creating a #{type}/#{post_type}..")
|
Logger.info("Creating a #{type}/#{post_type}..")
|
||||||
|
|
||||||
|
channel = Chiya.Channels.get_channel(default_channel_id)
|
||||||
|
|
||||||
case post_type do
|
case post_type do
|
||||||
:note -> get_note_attrs(properties, default_channel)
|
:note -> get_note_attrs(properties, channel)
|
||||||
_ -> {:error, :insufficient_scope}
|
_ -> {:error, :insufficient_scope}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -179,15 +181,19 @@ defmodule ChiyaWeb.Indie.MicropubHandler do
|
||||||
do: NaiveDateTime.local_now(),
|
do: NaiveDateTime.local_now(),
|
||||||
else: nil
|
else: nil
|
||||||
|
|
||||||
# TODO: Add default channel
|
attrs = %{
|
||||||
|
|
||||||
{:ok,
|
|
||||||
%{
|
|
||||||
content: content,
|
content: content,
|
||||||
name: name,
|
name: name,
|
||||||
tags_string: tags,
|
tags_string: tags,
|
||||||
published_at: published_at,
|
published_at: published_at
|
||||||
}}
|
}
|
||||||
|
|
||||||
|
attrs =
|
||||||
|
if default_channel,
|
||||||
|
do: Map.put(attrs, :channel, default_channel),
|
||||||
|
else: attrs
|
||||||
|
|
||||||
|
{:ok, attrs}
|
||||||
end
|
end
|
||||||
|
|
||||||
defp get_hostname(),
|
defp get_hostname(),
|
||||||
|
|
Loading…
Reference in a new issue