Remove duplicated helper functions, move them to utils package

This commit is contained in:
Deluan
2020-06-24 18:12:23 -04:00
committed by Deluan Quintão
parent bb9a7fadc0
commit eb109ebeb4
5 changed files with 61 additions and 21 deletions
+2 -7
View File
@@ -10,9 +10,7 @@ import (
"image/jpeg"
_ "image/png"
"io"
"mime"
"os"
"path/filepath"
"strings"
"time"
@@ -21,6 +19,7 @@ import (
"github.com/deluan/navidrome/log"
"github.com/deluan/navidrome/model"
"github.com/deluan/navidrome/resources"
"github.com/deluan/navidrome/utils"
"github.com/dhowden/tag"
"github.com/disintegration/imaging"
"github.com/djherbis/fscache"
@@ -141,7 +140,7 @@ func (c *cover) getCover(ctx context.Context, path string, size int) (reader io.
}
var data []byte
if isAudioFile(filepath.Ext(path)) {
if utils.IsAudioFile(path) {
data, err = readFromTag(path)
} else {
data, err = readFromFile(path)
@@ -207,10 +206,6 @@ func readFromFile(path string) ([]byte, error) {
return buf.Bytes(), nil
}
func isAudioFile(extension string) bool {
return strings.HasPrefix(mime.TypeByExtension(extension), "audio/")
}
func NewImageCache() (ImageCache, error) {
return newFileCache("Image", conf.Server.ImageCacheSize, consts.ImageCacheDir, consts.DefaultImageCacheMaxItems)
}