tstor/daemons/atorrent/generated/graphql/resolver/subscription.resolvers.go
royalcat 5b11b70370
All checks were successful
docker / build-docker (push) Successful in 5m42s
remove old torrent for better times
2025-01-08 01:25:46 +03:00

49 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
}