Fix regression: Show artwork in Music Stash when browsing by folder

This commit is contained in:
Deluan 2020-08-13 23:56:06 -04:00 committed by Deluan Quintão
parent 419884db7c
commit 0e16d7cfbb
2 changed files with 20 additions and 2 deletions

View File

@ -90,17 +90,25 @@ func (c *artwork) getImagePath(ctx context.Context, id string) (path string, las
}
log.Trace(ctx, "Looking for media file art", "id", id)
// if id is a mediafile cover id
// Check if id is a mediaFile cover id
var mf *model.MediaFile
mf, err = c.ds.MediaFile(ctx).Get(id)
// If it is not, may be an albumId
if err == model.ErrNotFound {
return c.getImagePath(ctx, "al-"+id)
}
if err != nil {
return
}
// If it is a mediaFile and it has cover art, return it
if mf.HasCoverArt {
return mf.Path, mf.UpdatedAt, nil
}
// if the mediafile does not have a coverArt, fallback to the album cover
// if the mediaFile does not have a coverArt, fallback to the album cover
log.Trace(ctx, "Media file does not contain art. Falling back to album art", "id", id, "albumId", "al-"+mf.AlbumID)
return c.getImagePath(ctx, "al-"+mf.AlbumID)
}

View File

@ -101,6 +101,16 @@ var _ = Describe("Artwork", func() {
Expect(format).To(Equal("jpeg"))
})
It("retrieves the album artwork by album id", func() {
buf := new(bytes.Buffer)
Expect(artwork.Get(ctx, "222", 0, buf)).To(BeNil())
_, format, err := image.Decode(bytes.NewReader(buf.Bytes()))
Expect(err).To(BeNil())
Expect(format).To(Equal("jpeg"))
})
It("resized artwork art as requested", func() {
buf := new(bytes.Buffer)