From c66b40f41586a7007624a3f75705560873db54d4 Mon Sep 17 00:00:00 2001 From: Deluan Date: Thu, 23 Jul 2026 19:48:46 -0400 Subject: [PATCH] feat(artwork): carry blurhash through item image hydration --- model/artwork.go | 1 + persistence/artwork_hydration.go | 1 + persistence/artwork_hydration_test.go | 29 +++++++++++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/model/artwork.go b/model/artwork.go index a21936535..7ba2ce21a 100644 --- a/model/artwork.go +++ b/model/artwork.go @@ -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. diff --git a/persistence/artwork_hydration.go b/persistence/artwork_hydration.go index bf1060055..7ec674065 100644 --- a/persistence/artwork_hydration.go +++ b/persistence/artwork_hydration.go @@ -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 } } diff --git a/persistence/artwork_hydration_test.go b/persistence/artwork_hydration_test.go index d9c80e054..d9eabdaaa 100644 --- a/persistence/artwork_hydration_test.go +++ b/persistence/artwork_hydration_test.go @@ -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()) + }) + }) })