43 lines
1.1 KiB
Go
43 lines
1.1 KiB
Go
package daemon
|
|
|
|
import (
|
|
"context"
|
|
|
|
graph "git.kmsign.ru/royalcat/tstor/plugins/qbittorrent/delivery/graphql"
|
|
"git.kmsign.ru/royalcat/tstor/plugins/qbittorrent/delivery/graphql/resolver"
|
|
"git.kmsign.ru/royalcat/tstor/plugins/qbittorrent/pkg/qbittorrent"
|
|
"git.kmsign.ru/royalcat/tstor/server/src/delivery"
|
|
"github.com/99designs/gqlgen/graphql"
|
|
)
|
|
|
|
func (d *QBittorrentDaemon) GraphQLSchema() graphql.ExecutableSchema {
|
|
return graph.NewExecutableSchema(graph.Config{
|
|
Resolvers: &resolver.Resolver{
|
|
QBitTorrentDaemon: d,
|
|
},
|
|
Directives: graph.DirectiveRoot{
|
|
Resolver: delivery.NoopDirective,
|
|
Stream: delivery.NoopDirective,
|
|
},
|
|
})
|
|
}
|
|
|
|
func (d *QBittorrentDaemon) ListTorrents(ctx context.Context) ([]*qbittorrent.TorrentInfo, error) {
|
|
return d.client.qb.Torrent().GetTorrents(ctx, &qbittorrent.TorrentOption{})
|
|
}
|
|
|
|
func (d *QBittorrentDaemon) SourceFiles(ctx context.Context, hash string) ([]string, error) {
|
|
d.sourceFilesMu.Lock()
|
|
defer d.sourceFilesMu.Unlock()
|
|
|
|
out := make([]string, 0, 1)
|
|
for k, h := range d.sourceFiles {
|
|
if h != hash {
|
|
continue
|
|
}
|
|
|
|
out = append(out, k)
|
|
}
|
|
|
|
return out, nil
|
|
}
|