navidrome/core/artwork.go

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

64 lines
1.4 KiB
Go
Raw Normal View History

package core
import (
"context"
2020-04-05 20:31:05 -04:00
"fmt"
_ "image/gif"
_ "image/png"
"io"
2020-10-27 17:02:20 -04:00
"sync"
"time"
2020-04-04 22:23:20 -04:00
"github.com/navidrome/navidrome/conf"
"github.com/navidrome/navidrome/consts"
2020-01-23 19:44:08 -05:00
"github.com/navidrome/navidrome/model"
"github.com/navidrome/navidrome/resources"
"github.com/navidrome/navidrome/utils/cache"
2020-08-21 11:33:23 -04:00
_ "golang.org/x/image/webp"
)
type Artwork interface {
2020-11-17 13:30:37 -05:00
Get(ctx context.Context, id string, size int) (io.ReadCloser, error)
}
2020-10-23 21:30:45 -04:00
type ArtworkCache cache.FileCache
2020-07-24 15:40:27 -04:00
func NewArtwork(ds model.DataStore, cache ArtworkCache) Artwork {
return &artwork{ds: ds, cache: cache}
}
type artwork struct {
2020-04-04 22:23:20 -04:00
ds model.DataStore
2020-10-23 21:30:45 -04:00
cache cache.FileCache
2020-07-24 13:30:27 -04:00
}
2022-12-19 13:59:24 -05:00
func (a *artwork) Get(ctx context.Context, id string, size int) (io.ReadCloser, error) {
return resources.FS().Open(consts.PlaceholderAlbumArt)
}
type imageInfo struct {
a *artwork
id string
2020-07-24 13:30:27 -04:00
path string
size int
lastUpdate time.Time
}
func (ci *imageInfo) Key() string {
2020-07-24 13:30:27 -04:00
return fmt.Sprintf("%s.%d.%s.%d", ci.path, ci.size, ci.lastUpdate.Format(time.RFC3339Nano), conf.Server.CoverJpegQuality)
}
2020-10-27 17:02:20 -04:00
var (
onceImageCache sync.Once
instanceImageCache ArtworkCache
)
func GetImageCache() ArtworkCache {
onceImageCache.Do(func() {
instanceImageCache = cache.NewFileCache("Image", conf.Server.ImageCacheSize, consts.ImageCacheDir, consts.DefaultImageCacheMaxItems,
func(ctx context.Context, arg cache.Item) (io.Reader, error) {
2022-12-19 13:59:24 -05:00
return nil, nil
2020-10-27 17:02:20 -04:00
})
})
return instanceImageCache
2020-04-04 22:23:20 -04:00
}