refactor: open track store explicitly and remove global state

This commit is contained in:
Mathis Maquenne
2026-08-05 11:34:27 +02:00
parent 714d567603
commit 0ab25addd5
7 changed files with 61 additions and 47 deletions
+4 -2
View File
@@ -23,6 +23,7 @@ const chunkSize = 2048
type Client struct {
appConfig *config.Config
store *store.Store
kind deezer.Kind
deezerClient *deezer.Client
@@ -31,9 +32,10 @@ type Client struct {
hashIndexErr error
}
func New(appConfig *config.Config, kind deezer.Kind) *Client {
func New(appConfig *config.Config, st *store.Store, kind deezer.Kind) *Client {
return &Client{
appConfig: appConfig,
store: st,
kind: kind,
}
}
@@ -249,7 +251,7 @@ func (c *Client) finalizeDownload(resource deezer.Resource, track *deezer.Track,
Downloaded: time.Now(),
}
if err := info.Save(); err != nil {
if err := c.store.PutDownloadInfo(info); err != nil {
warnings = append(warnings, fmt.Sprintf("failed to save download info: %v", err))
}
+2 -3
View File
@@ -4,11 +4,10 @@ import (
"context"
"github.com/mathismqn/godeez/internal/fileutil"
"github.com/mathismqn/godeez/internal/store"
)
func (c *Client) shouldSkipDownload(ctx context.Context, trackID, mediaFormat string) (string, bool) {
existing, err := store.GetDownloadInfo(trackID)
existing, err := c.store.DownloadInfo(trackID)
if err != nil || existing.Quality != mediaFormat {
return "", false
}
@@ -31,7 +30,7 @@ func (c *Client) shouldSkipDownload(ctx context.Context, trackID, mediaFormat st
}
existing.Path = foundPath
_ = existing.Save()
_ = c.store.PutDownloadInfo(existing)
return foundPath, true
}