diff --git a/lib/music_library/assets/transform.ex b/lib/music_library/assets/transform.ex index d1c72910..83c4936f 100644 --- a/lib/music_library/assets/transform.ex +++ b/lib/music_library/assets/transform.ex @@ -5,6 +5,8 @@ defmodule MusicLibrary.Assets.Transform do @type t :: %__MODULE__{} @type payload :: String.t() + def new(attrs \\ %{}), do: struct!(__MODULE__, attrs) + @doc """ iex> alias MusicLibrary.Assets.Transform iex> transform = %Transform{hash: "abc123", width: 300} diff --git a/lib/music_library_web/components/artist_components.ex b/lib/music_library_web/components/artist_components.ex index b1376c73..531dc5ce 100644 --- a/lib/music_library_web/components/artist_components.ex +++ b/lib/music_library_web/components/artist_components.ex @@ -10,7 +10,7 @@ defmodule MusicLibraryWeb.ArtistComponents do def artist_image(assigns) do payload = - %Transform{hash: assigns.image_hash, width: assigns.width} + Transform.new(hash: assigns.image_hash, width: assigns.width) |> Transform.encode!() assigns = assign(assigns, :payload, payload) diff --git a/lib/music_library_web/components/record_components.ex b/lib/music_library_web/components/record_components.ex index 37f73573..1d692934 100644 --- a/lib/music_library_web/components/record_components.ex +++ b/lib/music_library_web/components/record_components.ex @@ -12,7 +12,7 @@ defmodule MusicLibraryWeb.RecordComponents do def record_cover(assigns) do payload = - %Transform{hash: assigns.record.cover_hash, width: assigns.width} + Transform.new(hash: assigns.record.cover_hash, width: assigns.width) |> Transform.encode!() assigns = assign(assigns, :payload, payload) diff --git a/lib/music_library_web/controllers/collection_json.ex b/lib/music_library_web/controllers/collection_json.ex index 3afe1e85..34a37956 100644 --- a/lib/music_library_web/controllers/collection_json.ex +++ b/lib/music_library_web/controllers/collection_json.ex @@ -21,8 +21,8 @@ defmodule MusicLibraryWeb.CollectionJSON do id: record.id, artists: Enum.map(record.artists, & &1.name), title: record.title, - cover_url: url(~p"/api/assets/#{%Transform{hash: record.cover_hash}}"), - thumb_url: url(~p"/api/assets/#{%Transform{hash: record.cover_hash, width: 480}}") + cover_url: url(~p"/api/assets/#{Transform.new(hash: record.cover_hash)}"), + thumb_url: url(~p"/api/assets/#{Transform.new(hash: record.cover_hash, width: 480)}") } end end