提取cover服务
All checks were successful
Go CI / test-and-build (push) Successful in 11s

This commit is contained in:
2026-04-08 20:44:04 +08:00
parent 55c017f60d
commit 4bc160284d
6 changed files with 88 additions and 60 deletions

View File

@@ -1,16 +1,13 @@
package service
import (
"butterfliu/config"
"butterfliu/internal/model"
"butterfliu/internal/repository"
"butterfliu/internal/scanner"
"errors"
"fmt"
"log"
"path"
"path/filepath"
"strconv"
"strings"
)
@@ -23,7 +20,7 @@ type ScanReport struct {
}
type LibraryService struct {
libRepo *repository.LibraryRepository
libRepo *repository.LibraryRepository
artistRepo *repository.ArtistRepository
albumRepo *repository.AlbumRepository
songRepo *repository.SongRepository
@@ -169,18 +166,6 @@ func (s *LibraryService) GetAlbum(id int) (model.AlbumDetail, error) {
}, nil
}
func (s *LibraryService) GetAlbumCover(id int) (string, error) {
songs, err := s.albumRepo.GetSongIDs(id)
if err != nil {
return "", err
}
if len(songs) == 0 {
return "", errors.New("no songs found for album")
}
conf := config.LoadConfig()
return path.Join(conf.GetCachePath("cover"), strconv.Itoa(songs[0])+".jpg"), nil
}
func (s *LibraryService) Scan(id int) (*ScanReport, error) {
lib, err := s.libRepo.GetByID(id)
if err != nil {