devel #210
3 changed files with 23 additions and 7 deletions
|
@ -3,6 +3,11 @@ defmodule Chiya.Notes.NoteImage do
|
|||
use Waffle.Ecto.Schema
|
||||
import Ecto.Changeset
|
||||
|
||||
@attachment_options [
|
||||
allow_paths: true,
|
||||
allow_urls: true
|
||||
]
|
||||
|
||||
schema "note_images" do
|
||||
field :content, :string, default: ""
|
||||
field :path, ChiyaWeb.Uploaders.NoteImage.Type
|
||||
|
@ -24,7 +29,7 @@ defmodule Chiya.Notes.NoteImage do
|
|||
def update_changeset(note_image, attrs) do
|
||||
note_image
|
||||
|> cast(attrs, [:content, :note_id, :featured])
|
||||
|> cast_attachments(attrs, [:path], allow_paths: true)
|
||||
|> cast_attachments(attrs, [:path], @attachment_options)
|
||||
|> validate_required([:path, :note_id])
|
||||
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} <- Chiya.Notes.create_note(note_attrs) do
|
||||
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)}
|
||||
else
|
||||
error ->
|
||||
|
@ -60,8 +72,8 @@ defmodule ChiyaWeb.Indie.MicropubHandler do
|
|||
url = ChiyaWeb.Uploaders.UserImageTemp.url({image.path, image}, :original)
|
||||
{:ok, url}
|
||||
else
|
||||
_ ->
|
||||
{:error, :insufficient_scope}
|
||||
_ ->
|
||||
{:error, :insufficient_scope}
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -182,8 +194,7 @@ defmodule ChiyaWeb.Indie.MicropubHandler do
|
|||
content = Props.get_content(p)
|
||||
name = Props.get_title(p) || Chiya.Notes.Note.note_title(content)
|
||||
tags = Props.get_tags(p) |> Enum.join(",")
|
||||
photo = Props.get_photo(p)
|
||||
|
||||
|
||||
published_at =
|
||||
if Props.is_published?(p),
|
||||
do: NaiveDateTime.local_now(),
|
||||
|
|
|
@ -50,8 +50,8 @@ defmodule ChiyaWeb.Indie.Properties do
|
|||
def is_published?(%{"post-status" => ["draft"]} = _props), do: false
|
||||
def is_published?(_props), do: true
|
||||
|
||||
def get_photo(%{"photo" => [photo]} = _props), do: photo
|
||||
def get_photo(_props), do: nil
|
||||
def get_photos(%{"photo" => photos} = _props), do: photos
|
||||
def get_photos(_props), do: []
|
||||
|
||||
def get_syndication_targets(%{"mp-syndicate-to" => targets} = _props), do: targets
|
||||
def get_syndication_targets(_props), do: []
|
||||
|
|
Loading…
Reference in a new issue