Also caches resized images
This commit is contained in:
parent
dc16ccdb93
commit
e89d99aee0
|
@ -55,17 +55,6 @@ func (a *artwork) Get(ctx context.Context, id string, size int) (io.ReadCloser,
|
|||
}
|
||||
}
|
||||
|
||||
// If requested a resized image, get the original (possibly from cache)
|
||||
if size > 0 && id != "" {
|
||||
r, err := a.Get(ctx, id, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer r.Close()
|
||||
resized, err := a.resizedFromOriginal(ctx, artID, r, size)
|
||||
return io.NopCloser(resized), err
|
||||
}
|
||||
|
||||
key := &artworkKey{a: a, artID: artID, size: size}
|
||||
|
||||
r, err := a.cache.Get(ctx, key)
|
||||
|
@ -85,6 +74,17 @@ func (f fromFunc) String() string {
|
|||
}
|
||||
|
||||
func (a *artwork) get(ctx context.Context, artID model.ArtworkID, size int) (reader io.ReadCloser, path string, err error) {
|
||||
// If requested a resized image, get the original (possibly from cache)
|
||||
if size > 0 {
|
||||
r, err := a.Get(ctx, artID.String(), 0)
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
defer r.Close()
|
||||
resized, err := a.resizedFromOriginal(ctx, artID, r, size)
|
||||
return io.NopCloser(resized), fmt.Sprintf("%s@%d", artID, size), err
|
||||
}
|
||||
|
||||
switch artID.Kind {
|
||||
case model.KindAlbumArtwork:
|
||||
reader, path = a.extractAlbumImage(ctx, artID)
|
||||
|
|
|
@ -183,7 +183,7 @@ var _ = Describe("Artwork", func() {
|
|||
})
|
||||
It("returns a JPEG if original image is not a PNG", func() {
|
||||
conf.Server.CoverArtPriority = "cover.jpg"
|
||||
r, err := aw.Get(context.Background(), alMultipleCovers.CoverArtID().String(), 200)
|
||||
r, _, err := aw.get(context.Background(), alMultipleCovers.CoverArtID(), 200)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
br, format, err := asImageReader(r)
|
||||
|
|
Loading…
Reference in New Issue