mirror of
https://git.sr.ht/~phw/scotty
synced 2025-04-30 13:47:05 +02:00
Import result can report total and processed items
This commit is contained in:
parent
516de905bd
commit
ead323eaed
5 changed files with 14 additions and 7 deletions
|
@ -37,13 +37,15 @@ func (b DumpBackend) FromConfig(config *viper.Viper) models.Backend {
|
|||
|
||||
func (b DumpBackend) ImportListens(listens []models.Listen, oldestTimestamp time.Time) (models.ImportResult, error) {
|
||||
result := models.ImportResult{
|
||||
Count: len(listens),
|
||||
TotalCount: len(listens),
|
||||
ImportCount: 0,
|
||||
LastTimestamp: oldestTimestamp,
|
||||
}
|
||||
for _, listen := range listens {
|
||||
if listen.ListenedAt.Unix() > result.LastTimestamp.Unix() {
|
||||
result.LastTimestamp = listen.ListenedAt
|
||||
}
|
||||
result.ImportCount += 1
|
||||
fmt.Printf("🎶 %v: \"%s\" by %s\n", listen.ListenedAt, listen.TrackName, listen.ArtistName())
|
||||
}
|
||||
return result, nil
|
||||
|
@ -51,13 +53,15 @@ func (b DumpBackend) ImportListens(listens []models.Listen, oldestTimestamp time
|
|||
|
||||
func (b DumpBackend) ImportLoves(loves []models.Love, oldestTimestamp time.Time) (models.ImportResult, error) {
|
||||
result := models.ImportResult{
|
||||
Count: len(loves),
|
||||
TotalCount: len(loves),
|
||||
ImportCount: 0,
|
||||
LastTimestamp: oldestTimestamp,
|
||||
}
|
||||
for _, love := range loves {
|
||||
if love.Created.Unix() > result.LastTimestamp.Unix() {
|
||||
result.LastTimestamp = love.Created
|
||||
}
|
||||
result.ImportCount += 1
|
||||
fmt.Printf("❤️ %v: \"%s\" by %s\n", love.Created, love.TrackName, love.ArtistName())
|
||||
}
|
||||
return result, nil
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue