forked from navidrome/navidrome
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
169 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package artwork | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/navidrome/navidrome/log" | ||
"github.com/navidrome/navidrome/tests" | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestArtwork(t *testing.T) { | ||
tests.Init(t, false) | ||
log.SetLevel(log.LevelFatal) | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Artwork Suite") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package artwork_test | ||
|
||
import ( | ||
"context" | ||
"io" | ||
|
||
"github.com/navidrome/navidrome/conf" | ||
"github.com/navidrome/navidrome/conf/configtest" | ||
"github.com/navidrome/navidrome/consts" | ||
"github.com/navidrome/navidrome/core/artwork" | ||
"github.com/navidrome/navidrome/model" | ||
"github.com/navidrome/navidrome/resources" | ||
"github.com/navidrome/navidrome/tests" | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("Artwork", func() { | ||
var aw artwork.Artwork | ||
var ds model.DataStore | ||
var ffmpeg *tests.MockFFmpeg | ||
|
||
BeforeEach(func() { | ||
DeferCleanup(configtest.SetupConfig()) | ||
conf.Server.ImageCacheSize = "0" // Disable cache | ||
cache := artwork.GetImageCache() | ||
ffmpeg = tests.NewMockFFmpeg("content from ffmpeg") | ||
aw = artwork.NewArtwork(ds, cache, ffmpeg) | ||
}) | ||
|
||
Context("Empty ID", func() { | ||
It("returns placeholder if album is not in the DB", func() { | ||
r, _, err := aw.Get(context.Background(), "", 0) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
ph, err := resources.FS().Open(consts.PlaceholderAlbumArt) | ||
Expect(err).ToNot(HaveOccurred()) | ||
phBytes, err := io.ReadAll(ph) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
result, err := io.ReadAll(r) | ||
Expect(err).ToNot(HaveOccurred()) | ||
|
||
Expect(result).To(Equal(phBytes)) | ||
}) | ||
}) | ||
}) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package artwork | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"io" | ||
"time" | ||
|
||
"github.com/navidrome/navidrome/conf" | ||
"github.com/navidrome/navidrome/consts" | ||
"github.com/navidrome/navidrome/model" | ||
"github.com/navidrome/navidrome/utils/cache" | ||
"github.com/navidrome/navidrome/utils/singleton" | ||
) | ||
|
||
type cacheKey struct { | ||
artID model.ArtworkID | ||
size int | ||
lastUpdate time.Time | ||
} | ||
|
||
func (k *cacheKey) Key() string { | ||
return fmt.Sprintf( | ||
"%s.%d.%d.%d.%t", | ||
k.artID.ID, | ||
k.lastUpdate.UnixMilli(), | ||
k.size, | ||
conf.Server.CoverJpegQuality, | ||
conf.Server.EnableMediaFileCoverArt, | ||
) | ||
} | ||
|
||
type imageCache struct { | ||
cache.FileCache | ||
} | ||
|
||
func GetImageCache() cache.FileCache { | ||
return singleton.GetInstance(func() *imageCache { | ||
return &imageCache{ | ||
FileCache: cache.NewFileCache("Image", conf.Server.ImageCacheSize, consts.ImageCacheDir, consts.DefaultImageCacheMaxItems, | ||
func(ctx context.Context, arg cache.Item) (io.Reader, error) { | ||
r, _, err := arg.(artworkReader).Reader(ctx) | ||
return r, err | ||
}), | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.