feat: watch playlists and download newly added tracks

This commit is contained in:
Mathis Maquenne
2025-06-22 17:35:16 -04:00
parent 99bdc22a25
commit b19c92f227
8 changed files with 237 additions and 20 deletions
+6 -9
View File
@@ -16,6 +16,8 @@ type DownloadInfo struct {
Downloaded time.Time `json:"downloaded_at"`
}
var trackBucket = []byte("tracks")
func GetDownloadInfo(songID string) (*DownloadInfo, error) {
var info DownloadInfo
@@ -39,9 +41,9 @@ func GetDownloadInfo(songID string) (*DownloadInfo, error) {
func (d *DownloadInfo) Save() error {
return db.Update(func(tx *bbolt.Tx) error {
b := tx.Bucket(trackBucket)
if b == nil {
return fmt.Errorf("bucket not found")
b, err := tx.CreateBucketIfNotExists(trackBucket)
if err != nil {
return fmt.Errorf("failed to create bucket: %w", err)
}
data, err := json.Marshal(d)
@@ -49,11 +51,6 @@ func (d *DownloadInfo) Save() error {
return err
}
err = b.Put([]byte(d.SongID), data)
if err != nil {
return err
}
return nil
return b.Put([]byte(d.SongID), data)
})
}