mirror of
https://github.com/navidrome/navidrome.git
synced 2026-10-26 02:07:18 +01:00
feat(artwork): carry blurhash through item image hydration
This commit is contained in:
parent
a998a329e6
commit
c66b40f415
3 changed files with 31 additions and 0 deletions
|
|
@ -20,6 +20,7 @@ const ImageTypePrimary = "primary"
|
|||
type ItemImage struct {
|
||||
ImageHash string `structs:"-" json:"-"`
|
||||
ImageAbsent bool `structs:"-" json:"-"`
|
||||
BlurHash string `structs:"-" json:"-"`
|
||||
}
|
||||
|
||||
// ItemArtwork is an entity's resolved artwork state. Hash=="" means known absent.
|
||||
|
|
|
|||
|
|
@ -27,5 +27,6 @@ func applyItemImage(infos map[string]model.ItemArtworkInfo, id string, img *mode
|
|||
if info, ok := infos[id]; ok {
|
||||
img.ImageHash = info.Hash
|
||||
img.ImageAbsent = info.Absent()
|
||||
img.BlurHash = info.BlurHash
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -302,4 +302,33 @@ var _ = Describe("Artwork hydration", func() {
|
|||
Expect(res[0].ImageHash).To(Equal("alsrchhhhhhhhhhh"))
|
||||
})
|
||||
})
|
||||
|
||||
Describe("applyItemImage", func() {
|
||||
It("copies hash, absence and blurhash onto the item", func() {
|
||||
infos := map[string]model.ItemArtworkInfo{
|
||||
"al-1": {ItemID: "al-1", Hash: "0123456789abcdef", BlurHash: "LEHV6nWB2yk8"},
|
||||
}
|
||||
var img model.ItemImage
|
||||
applyItemImage(infos, "al-1", &img)
|
||||
Expect(img.ImageHash).To(Equal("0123456789abcdef"))
|
||||
Expect(img.ImageAbsent).To(BeFalse())
|
||||
Expect(img.BlurHash).To(Equal("LEHV6nWB2yk8"))
|
||||
})
|
||||
|
||||
It("marks a hashless entry absent and carries no blurhash", func() {
|
||||
infos := map[string]model.ItemArtworkInfo{"al-2": {ItemID: "al-2"}}
|
||||
var img model.ItemImage
|
||||
applyItemImage(infos, "al-2", &img)
|
||||
Expect(img.ImageAbsent).To(BeTrue())
|
||||
Expect(img.BlurHash).To(BeEmpty())
|
||||
})
|
||||
|
||||
It("leaves an unresolved item zero-valued", func() {
|
||||
var img model.ItemImage
|
||||
applyItemImage(map[string]model.ItemArtworkInfo{}, "al-3", &img)
|
||||
Expect(img.ImageHash).To(BeEmpty())
|
||||
Expect(img.ImageAbsent).To(BeFalse())
|
||||
Expect(img.BlurHash).To(BeEmpty())
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue