52 lines
1.5 KiB
Go
52 lines
1.5 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.72
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"slices"
|
|
|
|
graphql1 "git.kmsign.ru/royalcat/tstor/plugins/qbittorrent/delivery/graphql"
|
|
"git.kmsign.ru/royalcat/tstor/plugins/qbittorrent/delivery/graphql/model"
|
|
)
|
|
|
|
// Torrents is the resolver for the torrents field.
|
|
func (r *queryResolver) Torrents(ctx context.Context, filter *model.TorrentFilter) ([]*model.Torrent, error) {
|
|
info, err := r.QBitTorrentDaemon.ListTorrents(ctx)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error listing torrents: %w", err)
|
|
}
|
|
|
|
out := make([]*model.Torrent, len(info))
|
|
for i, v := range info {
|
|
out[i] = &model.Torrent{
|
|
Name: v.Name,
|
|
Hash: v.Hash,
|
|
}
|
|
}
|
|
|
|
if filter != nil {
|
|
if filter.SourcesCount != nil {
|
|
for _, t := range out {
|
|
srcs, err := r.QBitTorrentDaemon.SourceFiles(ctx, t.Hash)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("hash %s failed listing source files: %w", t.Hash, err)
|
|
}
|
|
t.SourceFiles = srcs
|
|
}
|
|
|
|
out = slices.DeleteFunc(out, func(t *model.Torrent) bool {
|
|
return !filter.SourcesCount.Include(int64(len(t.SourceFiles)))
|
|
})
|
|
}
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
// Query returns graphql1.QueryResolver implementation.
|
|
func (r *Resolver) Query() graphql1.QueryResolver { return &queryResolver{r} }
|
|
|
|
type queryResolver struct{ *Resolver }
|