mirror of
https://github.com/riwiwa/muzi.git
synced 2026-02-28 11:56:57 -08:00
remove redundant time parsing
This commit is contained in:
@@ -10,6 +10,7 @@ package migrate
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -335,19 +336,24 @@ func (s *trackSource) Err() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
batchStart += batchSize
|
// Implements custom JSON unmarshaling to parse the timestamp
|
||||||
|
func (s *SpotifyTrack) UnmarshalJSON(data []byte) error {
|
||||||
|
type Alias SpotifyTrack
|
||||||
|
aux := &struct {
|
||||||
|
Timestamp string `json:"ts"`
|
||||||
|
*Alias
|
||||||
|
}{
|
||||||
|
Alias: (*Alias)(s),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send completion update
|
if err := json.Unmarshal(data, &aux); err != nil {
|
||||||
if progressChan != nil {
|
return err
|
||||||
progressChan <- ProgressUpdate{
|
|
||||||
CurrentPage: totalBatches,
|
|
||||||
CompletedPages: totalBatches,
|
|
||||||
TotalPages: totalBatches,
|
|
||||||
TracksImported: totalImported,
|
|
||||||
Status: "completed",
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ts, err := time.Parse(time.RFC3339Nano, aux.Timestamp)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("parsing timestamp: %w", err)
|
||||||
|
}
|
||||||
|
s.Timestamp = ts
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user