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.
This commit is contained in:
Deluan 2026-07-18 00:24:46 -04:00
parent 5418e88f8e
commit b0aff3c9d6
2 changed files with 11 additions and 2 deletions

View File

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

View File

@ -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"))
})
})
})