56 lines
1.6 KiB
Go
56 lines
1.6 KiB
Go
package daemon
|
|
|
|
import (
|
|
"context"
|
|
|
|
"git.kmsign.ru/royalcat/tstor/plugins/qbittorrent/src/delivery/grpc/proto"
|
|
"git.kmsign.ru/royalcat/tstor/server/src/daemon"
|
|
"google.golang.org/grpc"
|
|
)
|
|
|
|
var _ daemon.DaemonWithGRPC = (*QBittorrentDaemon)(nil)
|
|
|
|
// RegisterGRPCService implements daemon.DaemonWithGRPC.
|
|
func (d *QBittorrentDaemon) RegisterGRPCService(server grpc.ServiceRegistrar) {
|
|
proto.RegisterQBitTorrentServiceServer(server, &grpcService{d: d})
|
|
}
|
|
|
|
type grpcService struct {
|
|
d *QBittorrentDaemon
|
|
// proto.UnimplementedQBitTorrentServiceServer
|
|
}
|
|
|
|
var _ proto.QBitTorrentServiceServer = (*grpcService)(nil)
|
|
|
|
// Cleanup implements proto.QBitTorrentServiceServer.
|
|
func (g *grpcService) Cleanup(ctx context.Context, req *proto.CleanupRequest) (*proto.CleanupResponse, error) {
|
|
hashes, err := g.d.Cleanup(ctx, req.GetAct())
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
resp := proto.CleanupResponse{}
|
|
resp.SetCount(int32(len(hashes)))
|
|
resp.SetHashes(hashes)
|
|
|
|
return &resp, nil
|
|
}
|
|
|
|
// CleanupUnregistred implements proto.QBitTorrentServiceServer.
|
|
func (g *grpcService) CleanupUnregistred(ctx context.Context, req *proto.CleanupUnregistredRequest) (*proto.CleanupUnregistredResponse, error) {
|
|
hashes, err := g.d.CleanupUnregistred(ctx, req.GetAct())
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
resp := proto.CleanupUnregistredResponse{}
|
|
resp.SetCount(int32(len(hashes)))
|
|
resp.SetHashes(hashes)
|
|
|
|
return &resp, nil
|
|
}
|
|
|
|
// GetTorrents implements proto.QBitTorrentServiceServer.
|
|
func (g *grpcService) GetTorrents(context.Context, *proto.GetTorrentsRequest) (*proto.GetTorrentsResponse, error) {
|
|
panic("not implemented") // TODO: Implement GetTorrents
|
|
}
|