feat(subsonic): scrobble to different scrobble backends in parallel
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
"unicode"
|
"unicode"
|
||||||
|
|
||||||
@@ -94,17 +95,26 @@ func (c *Controller) ServeScrobble(r *http.Request) *spec.Response {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var scrobbleErrs []error
|
var wg sync.WaitGroup
|
||||||
for _, scrobbler := range c.scrobblers {
|
|
||||||
if !scrobbler.IsUserAuthenticated(*user) {
|
scrobbleErrs := make([]error, len(c.scrobblers))
|
||||||
|
for i := range c.scrobblers {
|
||||||
|
if !c.scrobblers[i].IsUserAuthenticated(*user) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if err := scrobbler.Scrobble(*user, scrobbleTrack, optStamp, optSubmission); err != nil {
|
wg.Add(1)
|
||||||
scrobbleErrs = append(scrobbleErrs, err)
|
go func(i int) {
|
||||||
|
defer wg.Done()
|
||||||
|
if err := c.scrobblers[i].Scrobble(*user, scrobbleTrack, optStamp, optSubmission); err != nil {
|
||||||
|
scrobbleErrs[i] = err
|
||||||
}
|
}
|
||||||
|
}(i)
|
||||||
}
|
}
|
||||||
if len(scrobbleErrs) > 0 {
|
|
||||||
return spec.NewError(0, "error when submitting: %v", errors.Join(scrobbleErrs...))
|
wg.Wait()
|
||||||
|
|
||||||
|
if err := errors.Join(scrobbleErrs...); err != nil {
|
||||||
|
return spec.NewError(0, "error when submitting: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return spec.NewResponse()
|
return spec.NewResponse()
|
||||||
|
|||||||
Reference in New Issue
Block a user