Add image cache back

This commit is contained in:
Deluan
2022-12-20 11:27:40 -05:00
committed by Deluan Quintão
parent 40bb211b39
commit 0da27e8a3f
5 changed files with 96 additions and 41 deletions
+19 -12
View File
@@ -4,6 +4,8 @@ import (
"context"
"image"
"github.com/navidrome/navidrome/conf"
"github.com/navidrome/navidrome/conf/configtest"
"github.com/navidrome/navidrome/consts"
"github.com/navidrome/navidrome/log"
"github.com/navidrome/navidrome/model"
@@ -31,13 +33,18 @@ var _ = Describe("Artwork", func() {
mfWithEmbed = model.MediaFile{ID: "22", Path: "tests/fixtures/test.mp3", HasCoverArt: true, AlbumID: "222"}
mfWithoutEmbed = model.MediaFile{ID: "44", Path: "tests/fixtures/test.ogg", AlbumID: "444"}
mfCorruptedCover = model.MediaFile{ID: "45", Path: "tests/fixtures/test.ogg", HasCoverArt: true, AlbumID: "444"}
aw = NewArtwork(ds).(*artwork)
DeferCleanup(configtest.SetupConfig())
conf.Server.ImageCacheSize = "0" // Disable cache
cache := GetImageCache()
aw = NewArtwork(ds, cache).(*artwork)
})
Context("Albums", func() {
Context("ID not found", func() {
It("returns placeholder if album is not in the DB", func() {
_, path, err := aw.get(context.Background(), "al-NOT_FOUND-0", 0)
_, path, err := aw.get(context.Background(), model.MustParseArtworkID("al-NOT_FOUND-0"), 0)
Expect(err).ToNot(HaveOccurred())
Expect(path).To(Equal(consts.PlaceholderAlbumArt))
})
@@ -50,12 +57,12 @@ var _ = Describe("Artwork", func() {
})
})
It("returns embed cover", func() {
_, path, err := aw.get(context.Background(), alOnlyEmbed.CoverArtID().String(), 0)
_, path, err := aw.get(context.Background(), alOnlyEmbed.CoverArtID(), 0)
Expect(err).ToNot(HaveOccurred())
Expect(path).To(Equal("tests/fixtures/test.mp3"))
})
It("returns placeholder if embed path is not available", func() {
_, path, err := aw.get(context.Background(), alEmbedNotFound.CoverArtID().String(), 0)
_, path, err := aw.get(context.Background(), alEmbedNotFound.CoverArtID(), 0)
Expect(err).ToNot(HaveOccurred())
Expect(path).To(Equal(consts.PlaceholderAlbumArt))
})
@@ -68,17 +75,17 @@ var _ = Describe("Artwork", func() {
})
})
It("returns external cover", func() {
_, path, err := aw.get(context.Background(), alOnlyExternal.CoverArtID().String(), 0)
_, path, err := aw.get(context.Background(), alOnlyExternal.CoverArtID(), 0)
Expect(err).ToNot(HaveOccurred())
Expect(path).To(Equal("tests/fixtures/front.png"))
})
It("returns the first image if more than one is available", func() {
_, path, err := aw.get(context.Background(), alAllOptions.CoverArtID().String(), 0)
_, path, err := aw.get(context.Background(), alAllOptions.CoverArtID(), 0)
Expect(err).ToNot(HaveOccurred())
Expect(path).To(Equal("tests/fixtures/cover.jpg"))
})
It("returns placeholder if external file is not available", func() {
_, path, err := aw.get(context.Background(), alExternalNotFound.CoverArtID().String(), 0)
_, path, err := aw.get(context.Background(), alExternalNotFound.CoverArtID(), 0)
Expect(err).ToNot(HaveOccurred())
Expect(path).To(Equal(consts.PlaceholderAlbumArt))
})
@@ -87,7 +94,7 @@ var _ = Describe("Artwork", func() {
Context("MediaFiles", func() {
Context("ID not found", func() {
It("returns placeholder if album is not in the DB", func() {
_, path, err := aw.get(context.Background(), "mf-NOT_FOUND-0", 0)
_, path, err := aw.get(context.Background(), model.MustParseArtworkID("mf-NOT_FOUND-0"), 0)
Expect(err).ToNot(HaveOccurred())
Expect(path).To(Equal(consts.PlaceholderAlbumArt))
})
@@ -105,17 +112,17 @@ var _ = Describe("Artwork", func() {
})
})
It("returns embed cover", func() {
_, path, err := aw.get(context.Background(), mfWithEmbed.CoverArtID().String(), 0)
_, path, err := aw.get(context.Background(), mfWithEmbed.CoverArtID(), 0)
Expect(err).ToNot(HaveOccurred())
Expect(path).To(Equal("tests/fixtures/test.mp3"))
})
It("returns album cover if media file has no cover art", func() {
_, path, err := aw.get(context.Background(), mfWithoutEmbed.CoverArtID().String(), 0)
_, path, err := aw.get(context.Background(), mfWithoutEmbed.CoverArtID(), 0)
Expect(err).ToNot(HaveOccurred())
Expect(path).To(Equal("tests/fixtures/front.png"))
})
It("returns album cover if cannot read embed artwork", func() {
_, path, err := aw.get(context.Background(), mfCorruptedCover.CoverArtID().String(), 0)
_, path, err := aw.get(context.Background(), mfCorruptedCover.CoverArtID(), 0)
Expect(err).ToNot(HaveOccurred())
Expect(path).To(Equal("tests/fixtures/front.png"))
})
@@ -128,7 +135,7 @@ var _ = Describe("Artwork", func() {
})
})
It("returns external cover resized", func() {
r, path, err := aw.get(context.Background(), alOnlyExternal.CoverArtID().String(), 300)
r, path, err := aw.get(context.Background(), alOnlyExternal.CoverArtID(), 300)
Expect(err).ToNot(HaveOccurred())
Expect(path).To(Equal("tests/fixtures/front.png@300"))
img, _, err := image.Decode(r)