47 lines
1,021 B
Go
47 lines
1,021 B
Go
package graphql
|
|
|
|
// This file will be automatically regenerated based on the schema, any resolver implementations
|
|
// will be copied through when generating and any unknown code will be moved to the end.
|
|
// Code generated by github.com/99designs/gqlgen version v0.17.55
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
)
|
|
|
|
type subscriptionResolver struct{ *Resolver }
|
|
|
|
func (r *subscriptionResolver) TorrentDownloadUpdates(ctx context.Context) (<-chan *TorrentProgress, error) {
|
|
out := make(chan *TorrentProgress)
|
|
progress, err := r.ATorrentDaemon.DownloadProgress(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
go func() {
|
|
defer close(out)
|
|
for p := range progress {
|
|
if p.Torrent == nil {
|
|
fmt.Println("nil torrent")
|
|
continue
|
|
}
|
|
torrent, err := MapTorrent(ctx, p.Torrent)
|
|
if err != nil {
|
|
// TODO logs
|
|
continue
|
|
}
|
|
po := &TorrentProgress{
|
|
Torrent: torrent,
|
|
Current: p.Current,
|
|
Total: p.Total,
|
|
}
|
|
select {
|
|
case <-ctx.Done():
|
|
return
|
|
case out <- po:
|
|
}
|
|
}
|
|
}()
|
|
|
|
return out, nil
|
|
}
|