quintodrome/core/artwork.go

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

65 lines
1.4 KiB
Go
Raw Normal View History

package core
import (
"context"
2020-04-05 16:31:05 -08:00
"fmt"
_ "image/gif"
_ "image/png"
"io"
2020-10-27 13:02:20 -08:00
"sync"
"time"
2020-04-04 18:23:20 -08:00
"github.com/navidrome/navidrome/conf"
"github.com/navidrome/navidrome/consts"
2020-01-23 15:44:08 -09:00
"github.com/navidrome/navidrome/model"
"github.com/navidrome/navidrome/resources"
"github.com/navidrome/navidrome/utils/cache"
2020-08-21 07:33:23 -08:00
_ "golang.org/x/image/webp"
)
type Artwork interface {
2020-11-17 09:30:37 -09:00
Get(ctx context.Context, id string, size int) (io.ReadCloser, error)
}
2020-10-23 17:30:45 -08:00
type ArtworkCache cache.FileCache
2020-07-24 11:40:27 -08:00
func NewArtwork(ds model.DataStore, cache ArtworkCache) Artwork {
return &artwork{ds: ds, cache: cache}
}
type artwork struct {
2020-04-04 18:23:20 -08:00
ds model.DataStore
2020-10-23 17:30:45 -08:00
cache cache.FileCache
2020-07-24 09:30:27 -08:00
}
2022-12-19 09:59:24 -09: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 09:30:27 -08:00
path string
size int
lastUpdate time.Time
}
func (ci *imageInfo) Key() string {
2020-07-24 09:30:27 -08:00
return fmt.Sprintf("%s.%d.%s.%d", ci.path, ci.size, ci.lastUpdate.Format(time.RFC3339Nano), conf.Server.CoverJpegQuality)
}
2020-10-27 13:02:20 -08: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 09:59:24 -09:00
return nil, nil
2020-10-27 13:02:20 -08:00
})
})
return instanceImageCache
2020-04-04 18:23:20 -08:00
}