From b0aff3c9d6d0b8ae5f5fa887a2793a88aa429095 Mon Sep 17 00:00:00 2001 From: Deluan Date: Sat, 18 Jul 2026 00:24:46 -0400 Subject: [PATCH] fix(share): find the shared album in the loaded list for cover busting The loaded albums of a multi-album share are IN-fetched without preserving ResourceIDs order, so checking only index 0 could miss the shared album and fall back to the never-busting bare id. Search the list instead. --- model/share.go | 5 +++-- model/share_test.go | 8 ++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/model/share.go b/model/share.go index 9f49b6a2a..3723f001c 100644 --- a/model/share.go +++ b/model/share.go @@ -2,6 +2,7 @@ package model import ( "cmp" + "slices" "strings" "time" @@ -38,8 +39,8 @@ func (s Share) CoverArtID() ArtworkID { switch s.ResourceType { case "album": // Use the loaded album when available, so the public URL busts on cover edits - if len(s.Albums) > 0 && s.Albums[0].ID == ids[0] { - return s.Albums[0].CoverArtID() + if i := slices.IndexFunc(s.Albums, func(al Album) bool { return al.ID == ids[0] }); i >= 0 { + return s.Albums[i].CoverArtID() } return Album{ID: ids[0]}.CoverArtID() case "playlist": diff --git a/model/share_test.go b/model/share_test.go index 1304b960d..cf09043bf 100644 --- a/model/share_test.go +++ b/model/share_test.go @@ -20,5 +20,13 @@ var _ = Describe("Share", func() { Expect(s.CoverArtID().ID).To(Equal("al-1")) Expect(s.CoverArtID().String()).ToNot(Equal(plain)) }) + It("finds the shared album even when it is not first in the loaded list", func() { + stamp := time.Now() + s := Share{ResourceType: "album", ResourceIDs: "al-2,al-9"} + s.Albums = Albums{{ID: "al-9"}, {ID: "al-2", CoverArtUpdatedAt: &stamp}} + id := s.CoverArtID() + Expect(id.ID).To(Equal("al-2")) + Expect(id.String()).ToNot(HaveSuffix("_0")) + }) }) })