devel #210
3 changed files with 23 additions and 7 deletions
|
@ -3,6 +3,11 @@ defmodule Chiya.Notes.NoteImage do
|
||||||
use Waffle.Ecto.Schema
|
use Waffle.Ecto.Schema
|
||||||
import Ecto.Changeset
|
import Ecto.Changeset
|
||||||
|
|
||||||
|
@attachment_options [
|
||||||
|
allow_paths: true,
|
||||||
|
allow_urls: true
|
||||||
|
]
|
||||||
|
|
||||||
schema "note_images" do
|
schema "note_images" do
|
||||||
field :content, :string, default: ""
|
field :content, :string, default: ""
|
||||||
field :path, ChiyaWeb.Uploaders.NoteImage.Type
|
field :path, ChiyaWeb.Uploaders.NoteImage.Type
|
||||||
|
@ -24,7 +29,7 @@ defmodule Chiya.Notes.NoteImage do
|
||||||
def update_changeset(note_image, attrs) do
|
def update_changeset(note_image, attrs) do
|
||||||
note_image
|
note_image
|
||||||
|> cast(attrs, [:content, :note_id, :featured])
|
|> cast(attrs, [:content, :note_id, :featured])
|
||||||
|> cast_attachments(attrs, [:path], allow_paths: true)
|
|> cast_attachments(attrs, [:path], @attachment_options)
|
||||||
|> validate_required([:path, :note_id])
|
|> validate_required([:path, :note_id])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -28,6 +28,18 @@ defmodule ChiyaWeb.Indie.MicropubHandler do
|
||||||
{:ok, note_attrs} <- get_attrs(type, post_type, properties, micropub_channel_id),
|
{: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!")
|
||||||
|
|
||||||
|
# TODO: Make separate function for this
|
||||||
|
note_attrs
|
||||||
|
|> Props.get_photos()
|
||||||
|
|> Enum.map(fn photo_url ->
|
||||||
|
Chiya.Notes.create_note_image(%{
|
||||||
|
note_id: note.id,
|
||||||
|
path: photo_url
|
||||||
|
})
|
||||||
|
end)
|
||||||
|
|> Enum.each(&IO.inspect/1)
|
||||||
|
|
||||||
{:ok, :created, Chiya.Notes.Note.note_url(note)}
|
{:ok, :created, Chiya.Notes.Note.note_url(note)}
|
||||||
else
|
else
|
||||||
error ->
|
error ->
|
||||||
|
@ -61,7 +73,7 @@ defmodule ChiyaWeb.Indie.MicropubHandler do
|
||||||
{:ok, url}
|
{:ok, url}
|
||||||
else
|
else
|
||||||
_ ->
|
_ ->
|
||||||
{:error, :insufficient_scope}
|
{:error, :insufficient_scope}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -182,7 +194,6 @@ defmodule ChiyaWeb.Indie.MicropubHandler 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(",")
|
||||||
photo = Props.get_photo(p)
|
|
||||||
|
|
||||||
published_at =
|
published_at =
|
||||||
if Props.is_published?(p),
|
if Props.is_published?(p),
|
||||||
|
|
|
@ -50,8 +50,8 @@ defmodule ChiyaWeb.Indie.Properties do
|
||||||
def is_published?(%{"post-status" => ["draft"]} = _props), do: false
|
def is_published?(%{"post-status" => ["draft"]} = _props), do: false
|
||||||
def is_published?(_props), do: true
|
def is_published?(_props), do: true
|
||||||
|
|
||||||
def get_photo(%{"photo" => [photo]} = _props), do: photo
|
def get_photos(%{"photo" => photos} = _props), do: photos
|
||||||
def get_photo(_props), do: nil
|
def get_photos(_props), do: []
|
||||||
|
|
||||||
def get_syndication_targets(%{"mp-syndicate-to" => targets} = _props), do: targets
|
def get_syndication_targets(%{"mp-syndicate-to" => targets} = _props), do: targets
|
||||||
def get_syndication_targets(_props), do: []
|
def get_syndication_targets(_props), do: []
|
||||||
|
|
Loading…
Reference in a new issue