From abd3274250e84f849db6f9064dde75a0d6c686eb Mon Sep 17 00:00:00 2001 From: Deluan Date: Tue, 20 Dec 2022 11:34:01 -0500 Subject: [PATCH] Handle empty cover art ID in subsonic API --- core/artwork.go | 10 +++++++--- core/artwork_internal_test.go | 8 ++++++++ server/subsonic/media_retrieval.go | 2 +- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/core/artwork.go b/core/artwork.go index c07e62c48..5b2ddf609 100644 --- a/core/artwork.go +++ b/core/artwork.go @@ -41,9 +41,13 @@ type artwork struct { } func (a *artwork) Get(ctx context.Context, id string, size int) (io.ReadCloser, error) { - artID, err := model.ParseArtworkID(id) - if err != nil { - return nil, errors.New("invalid ID") + var artID model.ArtworkID + var err error + if id != "" { + artID, err = model.ParseArtworkID(id) + if err != nil { + return nil, errors.New("invalid ID") + } } key := &artworkKey{a: a, artID: artID, size: size} diff --git a/core/artwork_internal_test.go b/core/artwork_internal_test.go index 6139fd3fa..d0b2980ee 100644 --- a/core/artwork_internal_test.go +++ b/core/artwork_internal_test.go @@ -41,6 +41,14 @@ var _ = Describe("Artwork", func() { aw = NewArtwork(ds, cache).(*artwork) }) + Context("Empty ID", func() { + It("returns placeholder if album is not in the DB", func() { + _, path, err := aw.get(context.Background(), model.ArtworkID{}, 0) + Expect(err).ToNot(HaveOccurred()) + Expect(path).To(Equal(consts.PlaceholderAlbumArt)) + }) + }) + Context("Albums", func() { Context("ID not found", func() { It("returns placeholder if album is not in the DB", func() { diff --git a/server/subsonic/media_retrieval.go b/server/subsonic/media_retrieval.go index 78221c870..414edf8f3 100644 --- a/server/subsonic/media_retrieval.go +++ b/server/subsonic/media_retrieval.go @@ -51,7 +51,7 @@ func (api *Router) getPlaceHolderAvatar(w http.ResponseWriter, r *http.Request) } func (api *Router) GetCoverArt(w http.ResponseWriter, r *http.Request) (*responses.Subsonic, error) { - id := utils.ParamStringDefault(r, "id", "non-existent") + id := utils.ParamString(r, "id") size := utils.ParamInt(r, "size", 0) w.Header().Set("cache-control", "public, max-age=315360000")