devel #210

Merged
inhji merged 4 commits from devel into main 2023-07-17 19:01:23 +02:00
3 changed files with 23 additions and 7 deletions
Showing only changes of commit d9fd1bb08d - Show all commits

View file

@ -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

View file

@ -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 ->
@ -182,7 +194,6 @@ 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),

View file

@ -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: []