tstor/daemons/atorrent/delivery/graphql/subscription.resolvers.go

48 lines
1,021 B
Go
Raw Normal View History

2025-01-08 13:39:01 +00:00
package graphql
2025-01-07 22:25:46 +00:00
// 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 }
2025-01-08 13:39:01 +00:00
func (r *subscriptionResolver) TorrentDownloadUpdates(ctx context.Context) (<-chan *TorrentProgress, error) {
out := make(chan *TorrentProgress)
2025-01-07 22:25:46 +00:00
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
}
2025-01-08 13:39:01 +00:00
torrent, err := MapTorrent(ctx, p.Torrent)
2025-01-07 22:25:46 +00:00
if err != nil {
// TODO logs
continue
}
2025-01-08 13:39:01 +00:00
po := &TorrentProgress{
2025-01-07 22:25:46 +00:00
Torrent: torrent,
Current: p.Current,
Total: p.Total,
}
select {
case <-ctx.Done():
return
case out <- po:
}
}
}()
return out, nil
}