mirror of
https://git.sr.ht/~phw/scotty
synced 2025-05-12 02:57:04 +02:00
Initial implementation of unified export/import progress
Both export and import progress get updated over a unified channel. Most importantly this allows updating the import total from latest export results.
This commit is contained in:
parent
1f48abc284
commit
b8e6ccffdb
18 changed files with 369 additions and 194 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright © 2023 Philipp Wolfer <phw@uploadedlobster.com>
|
||||
Copyright © 2023-2025 Philipp Wolfer <phw@uploadedlobster.com>
|
||||
|
||||
This file is part of Scotty.
|
||||
|
||||
|
@ -72,21 +72,27 @@ func (b *SpotifyHistoryBackend) InitConfig(config *config.ServiceConfig) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (b *SpotifyHistoryBackend) ExportListens(oldestTimestamp time.Time, results chan models.ListensResult, progress chan models.Progress) {
|
||||
func (b *SpotifyHistoryBackend) ExportListens(oldestTimestamp time.Time, results chan models.ListensResult, progress chan models.TransferProgress) {
|
||||
files, err := filepath.Glob(path.Join(b.dirPath, historyFileGlob))
|
||||
p := models.TransferProgress{
|
||||
Export: &models.Progress{},
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
progress <- models.Progress{}.Abort()
|
||||
p.Export.Abort()
|
||||
progress <- p
|
||||
results <- models.ListensResult{Error: err}
|
||||
return
|
||||
}
|
||||
|
||||
slices.Sort(files)
|
||||
fileCount := int64(len(files))
|
||||
p := models.Progress{Total: fileCount}
|
||||
p.Export.Total = fileCount
|
||||
for i, filePath := range files {
|
||||
history, err := readHistoryFile(filePath)
|
||||
if err != nil {
|
||||
progress <- models.Progress{}.Abort()
|
||||
p.Export.Abort()
|
||||
progress <- p
|
||||
results <- models.ListensResult{Error: err}
|
||||
return
|
||||
}
|
||||
|
@ -97,11 +103,13 @@ func (b *SpotifyHistoryBackend) ExportListens(oldestTimestamp time.Time, results
|
|||
})
|
||||
sort.Sort(listens)
|
||||
results <- models.ListensResult{Items: listens}
|
||||
p.Elapsed = int64(i)
|
||||
p.Export.Elapsed = int64(i)
|
||||
p.Export.TotalItems += len(listens)
|
||||
progress <- p
|
||||
}
|
||||
|
||||
progress <- p.Complete()
|
||||
p.Export.Complete()
|
||||
progress <- p
|
||||
}
|
||||
|
||||
func readHistoryFile(filePath string) (StreamingHistory, error) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue