Also caches resized images
This commit is contained in:
+11
-11
@@ -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}
|
key := &artworkKey{a: a, artID: artID, size: size}
|
||||||
|
|
||||||
r, err := a.cache.Get(ctx, key)
|
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) {
|
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 {
|
switch artID.Kind {
|
||||||
case model.KindAlbumArtwork:
|
case model.KindAlbumArtwork:
|
||||||
reader, path = a.extractAlbumImage(ctx, artID)
|
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() {
|
It("returns a JPEG if original image is not a PNG", func() {
|
||||||
conf.Server.CoverArtPriority = "cover.jpg"
|
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())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
br, format, err := asImageReader(r)
|
br, format, err := asImageReader(r)
|
||||||
|
|||||||
Reference in New Issue
Block a user