Add vsn hash to artist image tag

This commit is contained in:
Claudio Ortolina
2025-04-29 16:16:18 +01:00
parent 5e9fba824c
commit f98e29263f
2 changed files with 17 additions and 12 deletions
@@ -65,14 +65,15 @@ defmodule MusicLibraryWeb.ArtistLive.Show do
socket socket
|> assign(:nav_section, :artists) |> assign(:nav_section, :artists)
|> assign(:artist, artist) |> assign(:artist, artist)
|> assign(:artist_info, artist_info)
|> assign(:country, ArtistInfo.country(artist_info)) |> assign(:country, ArtistInfo.country(artist_info))
|> stream(:collection_records, collection_records, reset: true) |> stream(:collection_records, collection_records, reset: true)
|> stream(:wishlist_records, wishlist_records, reset: true) |> stream(:wishlist_records, wishlist_records, reset: true)
|> assign(:collection_records_count, Enum.count(collection_records)) |> assign(:collection_records_count, Enum.count(collection_records))
|> assign(:wishlist_records_count, Enum.count(wishlist_records)) |> assign(:wishlist_records_count, Enum.count(wishlist_records))
|> assign_async(:artist_info, fn -> |> assign_async(:lastfm_artist_info, fn ->
with {:ok, artist_info} <- LastFm.get_artist_info(artist.musicbrainz_id, artist.name) do with {:ok, lastfm_artist_info} <- LastFm.get_artist_info(artist.musicbrainz_id, artist.name) do
{:ok, %{artist_info: artist_info}} {:ok, %{lastfm_artist_info: lastfm_artist_info}}
end end
end) end)
|> assign_async(:similar_artists, fn -> |> assign_async(:similar_artists, fn ->
@@ -6,7 +6,7 @@
</h1> </h1>
<div class="mt-4 flex items-center justify-between"> <div class="mt-4 flex items-center justify-between">
<.async_result :let={artist_info} assign={@artist_info}> <.async_result :let={lastfm_artist_info} assign={@lastfm_artist_info}>
<:loading> <:loading>
<div class="mt-4 text-zinc-700 dark:text-zinc-300"> <div class="mt-4 text-zinc-700 dark:text-zinc-300">
<span class="sr-only">{gettext("Loading play count")}</span> <span class="sr-only">{gettext("Loading play count")}</span>
@@ -29,17 +29,21 @@
{gettext("Error loading play count")} {gettext("Error loading play count")}
</div> </div>
</:failed> </:failed>
<a :if={artist_info.on_tour} href={LastFm.Artist.events_url(artist_info)} target="_blank"> <a
:if={lastfm_artist_info.on_tour}
href={LastFm.Artist.events_url(lastfm_artist_info)}
target="_blank"
>
<.round_badge text={gettext("On Tour")} class="mr-2" /> <.round_badge text={gettext("On Tour")} class="mr-2" />
</a> </a>
<span <span
:if={artist_info.play_count > 0} :if={lastfm_artist_info.play_count > 0}
class="text-xs font-medium text-zinc-700 dark:text-zinc-300 grow" class="text-xs font-medium text-zinc-700 dark:text-zinc-300 grow"
> >
{ngettext("1 scrobble", "%{count} scrobbles", artist_info.play_count)} {ngettext("1 scrobble", "%{count} scrobbles", lastfm_artist_info.play_count)}
</span> </span>
<span <span
:if={artist_info.play_count == 0} :if={lastfm_artist_info.play_count == 0}
class="text-xs font-medium text-zinc-700 dark:text-zinc-300 grow" class="text-xs font-medium text-zinc-700 dark:text-zinc-300 grow"
> >
{gettext("No scrobbles")} {gettext("No scrobbles")}
@@ -69,11 +73,11 @@
</h2> </h2>
<img <img
class="w-full rounded-md shadow-sm mt-4" class="w-full rounded-md shadow-sm mt-4"
src={~p"/artists/#{@artist.musicbrainz_id}/image"} src={~p"/artists/#{@artist_info.id}/image?vsn=#{@artist_info.image_data_hash}"}
alt={@artist.name} alt={@artist.name}
onerror={"this.src = '" <> ~p"/images/cover-not-found.png" <> "';"} onerror={"this.src = '" <> ~p"/images/cover-not-found.png" <> "';"}
/> />
<.async_result :let={artist_info} assign={@artist_info}> <.async_result :let={lastfm_artist_info} assign={@lastfm_artist_info}>
<:loading> <:loading>
<div class="mt-4 text-sm leading-5 text-zinc-500 dark:text-zinc-400"> <div class="mt-4 text-sm leading-5 text-zinc-500 dark:text-zinc-400">
{gettext("Loading biography")} {gettext("Loading biography")}
@@ -91,11 +95,11 @@
</div> </div>
</:failed> </:failed>
<details <details
:if={artist_info.bio !== ""} :if={lastfm_artist_info.bio !== ""}
class="text-sm leading-5 text-zinc-500 dark:text-zinc-400" class="text-sm leading-5 text-zinc-500 dark:text-zinc-400"
> >
<summary class="text-sm mt-4 mb-4">{gettext("Biography")}</summary> <summary class="text-sm mt-4 mb-4">{gettext("Biography")}</summary>
{render_bio(@artist_info.result.summary)} {render_bio(@lastfm_artist_info.result.summary)}
</details> </details>
</.async_result> </.async_result>