make linter happy
This commit is contained in:
@@ -60,7 +60,7 @@ func main() {
|
|||||||
log.Fatalf("couldn't create cache path: %v\n", err)
|
log.Fatalf("couldn't create cache path: %v\n", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
coverCachePath := path.Join(*cachePath, "covers")
|
coverCachePath := path.Join(*cachePath, coverCachePrefix)
|
||||||
if _, err := os.Stat(coverCachePath); os.IsNotExist(err) {
|
if _, err := os.Stat(coverCachePath); os.IsNotExist(err) {
|
||||||
if err := os.MkdirAll(coverCachePath, os.ModePerm); err != nil {
|
if err := os.MkdirAll(coverCachePath, os.ModePerm); err != nil {
|
||||||
log.Fatalf("couldn't create cover cache path: %v\n", err)
|
log.Fatalf("couldn't create cover cache path: %v\n", err)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package ctrlsubsonic
|
package ctrlsubsonic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
@@ -61,6 +62,11 @@ const (
|
|||||||
coverCacheFormat = "png"
|
coverCacheFormat = "png"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
errCoverNotFound = errors.New("could not find a cover with that id")
|
||||||
|
errCoverEmpty = errors.New("no cover found for that folder")
|
||||||
|
)
|
||||||
|
|
||||||
func coverGetPath(dbc *db.DB, musicPath string, id int) (string, error) {
|
func coverGetPath(dbc *db.DB, musicPath string, id int) (string, error) {
|
||||||
folder := &db.Album{}
|
folder := &db.Album{}
|
||||||
err := dbc.DB.
|
err := dbc.DB.
|
||||||
@@ -68,10 +74,10 @@ func coverGetPath(dbc *db.DB, musicPath string, id int) (string, error) {
|
|||||||
First(folder, id).
|
First(folder, id).
|
||||||
Error
|
Error
|
||||||
if gorm.IsRecordNotFoundError(err) {
|
if gorm.IsRecordNotFoundError(err) {
|
||||||
return "", fmt.Errorf("could not find a cover with that id")
|
return "", errCoverNotFound
|
||||||
}
|
}
|
||||||
if folder.Cover == "" {
|
if folder.Cover == "" {
|
||||||
return "", fmt.Errorf("no cover found for that folder")
|
return "", errCoverEmpty
|
||||||
}
|
}
|
||||||
return path.Join(
|
return path.Join(
|
||||||
musicPath,
|
musicPath,
|
||||||
@@ -84,7 +90,7 @@ func coverGetPath(dbc *db.DB, musicPath string, id int) (string, error) {
|
|||||||
func coverScaleAndSave(absPath, cachePath string, size int) error {
|
func coverScaleAndSave(absPath, cachePath string, size int) error {
|
||||||
src, err := imaging.Open(absPath)
|
src, err := imaging.Open(absPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("resizing `%s`: %v", absPath, err)
|
return fmt.Errorf("resizing `%s`: %w", absPath, err)
|
||||||
}
|
}
|
||||||
width := size
|
width := size
|
||||||
if width > src.Bounds().Dx() {
|
if width > src.Bounds().Dx() {
|
||||||
@@ -93,7 +99,7 @@ func coverScaleAndSave(absPath, cachePath string, size int) error {
|
|||||||
}
|
}
|
||||||
err = imaging.Save(imaging.Resize(src, width, 0, imaging.Lanczos), cachePath)
|
err = imaging.Save(imaging.Resize(src, width, 0, imaging.Lanczos), cachePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("caching `%s`: %v", cachePath, err)
|
return fmt.Errorf("caching `%s`: %w", cachePath, err)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user