mirror of
https://github.com/navidrome/navidrome.git
synced 2026-08-31 07:30:32 +00:00
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:
parent
5418e88f8e
commit
b0aff3c9d6
@ -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":
|
||||
|
||||
@ -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"))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user