Implemented progressbar for export/import

This commit is contained in:
Philipp Wolfer 2023-11-16 00:45:00 +01:00
parent ab04eb1123
commit 6e330daf06
No known key found for this signature in database
GPG key ID: 8FDF744D4919943B
24 changed files with 590 additions and 239 deletions

View file

@ -36,7 +36,7 @@ type SubsonicApiBackend struct {
password string
}
func (b SubsonicApiBackend) FromConfig(config *viper.Viper) models.Backend {
func (b *SubsonicApiBackend) FromConfig(config *viper.Viper) models.Backend {
b.client = subsonic.Client{
Client: &http.Client{},
BaseUrl: config.GetString("server-url"),
@ -47,8 +47,9 @@ func (b SubsonicApiBackend) FromConfig(config *viper.Viper) models.Backend {
return b
}
func (b SubsonicApiBackend) ExportLoves(oldestTimestamp time.Time, results chan models.LovesResult) {
func (b *SubsonicApiBackend) ExportLoves(oldestTimestamp time.Time, results chan models.LovesResult, progress chan models.Progress) {
defer close(results)
defer close(progress)
err := b.client.Authenticate(b.password)
if err != nil {
results <- models.LovesResult{Error: err}
@ -61,10 +62,11 @@ func (b SubsonicApiBackend) ExportLoves(oldestTimestamp time.Time, results chan
return
}
progress <- models.Progress{Elapsed: int64(len(starred.Song))}.Complete()
results <- models.LovesResult{Loves: b.filterSongs(starred.Song, oldestTimestamp)}
}
func (b SubsonicApiBackend) filterSongs(songs []*subsonic.Child, oldestTimestamp time.Time) models.LovesList {
func (b *SubsonicApiBackend) filterSongs(songs []*subsonic.Child, oldestTimestamp time.Time) models.LovesList {
loves := make(models.LovesList, len(songs))
for i, song := range songs {
love := SongToLove(*song, b.client.User)

View file

@ -35,8 +35,8 @@ func TestFromConfig(t *testing.T) {
config := viper.New()
config.Set("server-url", "https://subsonic.example.com")
config.Set("token", "thetoken")
backend := subsonic.SubsonicApiBackend{}.FromConfig(config)
assert.IsType(t, subsonic.SubsonicApiBackend{}, backend)
backend := (&subsonic.SubsonicApiBackend{}).FromConfig(config)
assert.IsType(t, &subsonic.SubsonicApiBackend{}, backend)
}
func TestSongToLove(t *testing.T) {