mirror of
https://github.com/navidrome/navidrome.git
synced 2026-08-31 07:30:32 +00:00
feat(nativeapi): expose artwork hash, absence and blurhash
This commit is contained in:
parent
c66b40f415
commit
9bb685a6af
@ -13,7 +13,7 @@ import (
|
||||
|
||||
type Album struct {
|
||||
Annotations `structs:"-" hash:"ignore"`
|
||||
ItemImage `structs:"-" json:"-" hash:"ignore"`
|
||||
ItemImage `structs:"-" hash:"ignore"`
|
||||
|
||||
ID string `structs:"id" json:"id"`
|
||||
LibraryID int `structs:"library_id" json:"libraryId"`
|
||||
|
||||
@ -11,7 +11,7 @@ import (
|
||||
|
||||
type Artist struct {
|
||||
Annotations `structs:"-"`
|
||||
ItemImage `structs:"-" json:"-"`
|
||||
ItemImage `structs:"-"`
|
||||
|
||||
ID string `structs:"id" json:"id"`
|
||||
|
||||
|
||||
@ -16,11 +16,11 @@ type Artwork struct {
|
||||
const ImageTypePrimary = "primary"
|
||||
|
||||
// ItemImage is per-entity artwork state hydrated at query time; never persisted
|
||||
// (structs:"-" keeps it out of upserts) nor exposed via the native API (json:"-").
|
||||
// (structs:"-" keeps it out of upserts).
|
||||
type ItemImage struct {
|
||||
ImageHash string `structs:"-" json:"-"`
|
||||
ImageAbsent bool `structs:"-" json:"-"`
|
||||
BlurHash string `structs:"-" json:"-"`
|
||||
ImageHash string `structs:"-" json:"imageHash,omitempty"`
|
||||
ImageAbsent bool `structs:"-" json:"imageAbsent,omitempty"`
|
||||
BlurHash string `structs:"-" json:"blurHash,omitempty"`
|
||||
}
|
||||
|
||||
// ItemArtwork is an entity's resolved artwork state. Hash=="" means known absent.
|
||||
|
||||
48
model/artwork_test.go
Normal file
48
model/artwork_test.go
Normal file
@ -0,0 +1,48 @@
|
||||
package model_test
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/navidrome/navidrome/model"
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
var _ = Describe("ItemImage JSON", func() {
|
||||
It("exposes artwork state on an album", func() {
|
||||
al := model.Album{ID: "al-1", Name: "Album"}
|
||||
al.ImageHash = "0123456789abcdef"
|
||||
al.BlurHash = "LEHV6nWB2yk8"
|
||||
|
||||
var out map[string]any
|
||||
data, err := json.Marshal(al)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(json.Unmarshal(data, &out)).To(Succeed())
|
||||
|
||||
Expect(out).To(HaveKeyWithValue("imageHash", "0123456789abcdef"))
|
||||
Expect(out).To(HaveKeyWithValue("blurHash", "LEHV6nWB2yk8"))
|
||||
})
|
||||
|
||||
It("omits artwork state when the entity has none", func() {
|
||||
var out map[string]any
|
||||
data, err := json.Marshal(model.Album{ID: "al-2", Name: "Album"})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(json.Unmarshal(data, &out)).To(Succeed())
|
||||
|
||||
Expect(out).ToNot(HaveKey("imageHash"))
|
||||
Expect(out).ToNot(HaveKey("blurHash"))
|
||||
Expect(out).ToNot(HaveKey("imageAbsent"))
|
||||
})
|
||||
|
||||
It("exposes known-absent artwork so clients can skip the request", func() {
|
||||
ar := model.Artist{ID: "ar-1", Name: "Artist"}
|
||||
ar.ImageAbsent = true
|
||||
|
||||
var out map[string]any
|
||||
data, err := json.Marshal(ar)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(json.Unmarshal(data, &out)).To(Succeed())
|
||||
|
||||
Expect(out).To(HaveKeyWithValue("imageAbsent", true))
|
||||
})
|
||||
})
|
||||
@ -24,7 +24,7 @@ import (
|
||||
type MediaFile struct {
|
||||
Annotations `structs:"-" hash:"ignore"`
|
||||
Bookmarkable `structs:"-" hash:"ignore"`
|
||||
ItemImage `structs:"-" json:"-" hash:"ignore"`
|
||||
ItemImage `structs:"-" hash:"ignore"`
|
||||
|
||||
ID string `structs:"id" json:"id" hash:"ignore"`
|
||||
PID string `structs:"pid" json:"-" hash:"ignore"`
|
||||
|
||||
@ -13,7 +13,7 @@ import (
|
||||
|
||||
type Playlist struct {
|
||||
Annotations `structs:"-"`
|
||||
ItemImage `structs:"-" json:"-"`
|
||||
ItemImage `structs:"-"`
|
||||
|
||||
ID string `structs:"id" json:"id"`
|
||||
Name string `structs:"name" json:"name"`
|
||||
|
||||
@ -7,7 +7,7 @@ import (
|
||||
)
|
||||
|
||||
type Radio struct {
|
||||
ItemImage `structs:"-" json:"-"`
|
||||
ItemImage `structs:"-"`
|
||||
|
||||
ID string `structs:"id" json:"id"`
|
||||
StreamUrl string `structs:"stream_url" json:"streamUrl"`
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user