50 lines
1.1 KiB
Go
50 lines
1.1 KiB
Go
|
package resolver
|
||
|
|
||
|
// 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"
|
||
|
|
||
|
"git.kmsign.ru/royalcat/tstor/daemons/atorrent/generated/graphql/model"
|
||
|
)
|
||
|
|
||
|
type subscriptionResolver struct{ *Resolver }
|
||
|
|
||
|
func (r *subscriptionResolver) TorrentDownloadUpdates(ctx context.Context) (<-chan *model.TorrentProgress, error) {
|
||
|
out := make(chan *model.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 := model.MapTorrent(ctx, p.Torrent)
|
||
|
if err != nil {
|
||
|
// TODO logs
|
||
|
continue
|
||
|
}
|
||
|
po := &model.TorrentProgress{
|
||
|
Torrent: torrent,
|
||
|
Current: p.Current,
|
||
|
Total: p.Total,
|
||
|
}
|
||
|
select {
|
||
|
case <-ctx.Done():
|
||
|
return
|
||
|
case out <- po:
|
||
|
}
|
||
|
}
|
||
|
}()
|
||
|
|
||
|
return out, nil
|
||
|
}
|