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 -6
View File
@@ -2,7 +2,6 @@ package persistence
import (
"context"
"mime"
"os"
"path/filepath"
"sort"
@@ -16,6 +15,7 @@ import (
"github.com/deluan/navidrome/consts"
"github.com/deluan/navidrome/log"
"github.com/deluan/navidrome/model"
"github.com/deluan/navidrome/utils"
"github.com/deluan/rest"
)
@@ -222,7 +222,7 @@ func getCoverFromPath(path string, hasEmbeddedCover bool) string {
for _, name := range names {
match, _ := filepath.Match(pat, strings.ToLower(name))
if match && isImageFile(filepath.Ext(name)) {
if match && utils.IsImageFile(name) {
return filepath.Join(filepath.Dir(path), name)
}
}
@@ -231,10 +231,6 @@ func getCoverFromPath(path string, hasEmbeddedCover bool) string {
return ""
}
func isImageFile(extension string) bool {
return strings.HasPrefix(mime.TypeByExtension(extension), "image/")
}
func (r *albumRepository) purgeEmpty() error {
del := Delete(r.tableName).Where("id not in (select distinct(album_id) from media_file)")
c, err := r.executeSQL(del)