Add blurhash support to backend
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -5,21 +5,32 @@ defmodule Mobilizon.Medias.Media do
|
||||
|
||||
use Ecto.Schema
|
||||
|
||||
import Ecto.Changeset, only: [cast: 3, cast_embed: 2]
|
||||
import Ecto.Changeset, only: [cast: 3, cast_embed: 2, cast_embed: 3]
|
||||
|
||||
alias Mobilizon.Actors.Actor
|
||||
alias Mobilizon.Discussions.Comment
|
||||
alias Mobilizon.Events.Event
|
||||
alias Mobilizon.Medias.File
|
||||
alias Mobilizon.Medias.Media.Metadata
|
||||
alias Mobilizon.Posts.Post
|
||||
|
||||
@type t :: %__MODULE__{
|
||||
file: File.t(),
|
||||
metadata: Metadata.t(),
|
||||
actor: Actor.t()
|
||||
}
|
||||
|
||||
@metadata_attrs [:height, :width, :blurhash]
|
||||
|
||||
schema "medias" do
|
||||
embeds_one(:file, File, on_replace: :update)
|
||||
|
||||
embeds_one :metadata, Metadata, on_replace: :update do
|
||||
field(:height, :integer)
|
||||
field(:width, :integer)
|
||||
field(:blurhash, :string)
|
||||
end
|
||||
|
||||
belongs_to(:actor, Actor)
|
||||
has_many(:event_picture, Event, foreign_key: :picture_id)
|
||||
many_to_many(:events, Event, join_through: "events_medias")
|
||||
@@ -36,5 +47,13 @@ defmodule Mobilizon.Medias.Media do
|
||||
media
|
||||
|> cast(attrs, [:actor_id])
|
||||
|> cast_embed(:file)
|
||||
|> cast_embed(:metadata, with: &metadata_changeset/2)
|
||||
end
|
||||
|
||||
@doc false
|
||||
@spec changeset(struct(), map) :: Ecto.Changeset.t()
|
||||
def metadata_changeset(metadata, attrs) do
|
||||
metadata
|
||||
|> cast(attrs, @metadata_attrs)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user