feat(artwork): carry blurhash through item image hydration

This commit is contained in:
Deluan 2026-07-23 19:48:46 -04:00
parent a998a329e6
commit c66b40f415
3 changed files with 31 additions and 0 deletions

View File

@ -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.

View File

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

View File

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