Handle empty cover art ID in subsonic API

This commit is contained in:
Deluan 2022-12-20 11:34:01 -05:00 committed by Deluan Quintão
parent 0da27e8a3f
commit abd3274250
3 changed files with 16 additions and 4 deletions

View File

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

View File

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

View File

@ -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")