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
+1 -20
View File
@@ -6,7 +6,6 @@ import (
"path/filepath"
"github.com/mathismqn/godeez/internal/fileutil"
"github.com/mathismqn/godeez/internal/store"
)
type Config struct {
@@ -14,7 +13,7 @@ type Config struct {
OutputDir string
}
func New() (*Config, error) {
func Load() (*Config, error) {
arl := os.Getenv("DEEZER_ARL")
homeDir, err := os.UserHomeDir()
@@ -27,24 +26,6 @@ func New() (*Config, error) {
return nil, fmt.Errorf("failed to create output directory: %w", err)
}
// Migrate tracks.db from ~/.godeez/ to output dir
oldDB := filepath.Join(homeDir, ".godeez", "tracks.db")
newDB := filepath.Join(outputDir, ".tracks.db")
if _, err := os.Stat(oldDB); err == nil {
if _, err := os.Stat(newDB); os.IsNotExist(err) {
os.Rename(oldDB, newDB)
}
}
// Clean up old config directory
oldDir := filepath.Join(homeDir, ".godeez")
os.Remove(filepath.Join(oldDir, "config.toml"))
os.Remove(oldDir) // fails silently if not empty
if err := store.OpenDB(outputDir); err != nil {
return nil, err
}
return &Config{
ARLCookie: arl,
OutputDir: outputDir,