2020-07-10 12:45:58 -04:00
|
|
|
package core
|
2016-03-08 23:05:54 -05:00
|
|
|
|
|
|
|
|
import (
|
2020-01-22 08:32:31 -05:00
|
|
|
"context"
|
2020-04-05 20:31:05 -04:00
|
|
|
"fmt"
|
2016-03-08 23:31:48 -05:00
|
|
|
_ "image/gif"
|
2016-03-18 11:33:50 -04:00
|
|
|
_ "image/png"
|
|
|
|
|
"io"
|
2020-10-27 17:02:20 -04:00
|
|
|
"sync"
|
2020-04-05 17:53:55 -04:00
|
|
|
"time"
|
2016-03-08 23:31:48 -05:00
|
|
|
|
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"
|
2020-05-01 14:35:57 -04:00
|
|
|
"github.com/navidrome/navidrome/resources"
|
2021-02-09 11:33:26 -05:00
|
|
|
"github.com/navidrome/navidrome/utils/cache"
|
2020-08-21 11:33:23 -04:00
|
|
|
_ "golang.org/x/image/webp"
|
2016-03-08 23:05:54 -05:00
|
|
|
)
|
|
|
|
|
|
2020-07-31 09:31:19 -04:00
|
|
|
type Artwork interface {
|
2020-11-17 13:30:37 -05:00
|
|
|
Get(ctx context.Context, id string, size int) (io.ReadCloser, error)
|
2016-03-08 23:05:54 -05:00
|
|
|
}
|
|
|
|
|
|
2020-10-23 21:30:45 -04:00
|
|
|
type ArtworkCache cache.FileCache
|
2020-07-24 15:40:27 -04:00
|
|
|
|
2020-07-31 09:31:19 -04:00
|
|
|
func NewArtwork(ds model.DataStore, cache ArtworkCache) Artwork {
|
|
|
|
|
return &artwork{ds: ds, cache: cache}
|
2016-03-08 23:05:54 -05:00
|
|
|
}
|
|
|
|
|
|
2020-07-31 09:31:19 -04:00
|
|
|
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)
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-31 09:31:19 -04:00
|
|
|
type imageInfo struct {
|
2020-10-24 15:10:27 -04:00
|
|
|
a *artwork
|
2020-10-24 14:58:58 -04:00
|
|
|
id string
|
2020-07-24 13:30:27 -04:00
|
|
|
path string
|
|
|
|
|
size int
|
|
|
|
|
lastUpdate time.Time
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-24 15:10:27 -04:00
|
|
|
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)
|
2016-03-30 10:01:37 -04:00
|
|
|
}
|
|
|
|
|
|
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
|
|
|
}
|