Skip to content

Commit 50509af

Browse files
Alexey SharpAlexey Sharp
authored andcommitted
Fixes
1 parent 64a26df commit 50509af

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

cmd/downloader/downloader/grpc_server.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ type GrpcServer struct {
6060
}
6161

6262
func (s *GrpcServer) Download(ctx context.Context, request *proto_downloader.DownloadRequest) (*emptypb.Empty, error) {
63+
mi := &metainfo.MetaInfo{AnnounceList: Trackers}
6364
infoHashes := make([]metainfo.Hash, len(request.Items))
6465
for i, it := range request.Items {
6566
if it.TorrentHash == nil {
@@ -74,6 +75,12 @@ func (s *GrpcServer) Download(ctx context.Context, request *proto_downloader.Dow
7475
} else {
7576
infoHashes[i] = gointerfaces.ConvertH160toAddress(it.TorrentHash)
7677
}
78+
if _, ok := s.t.TorrentClient.Torrent(infoHashes[i]); !ok {
79+
magnet := mi.Magnet(&infoHashes[i], nil)
80+
if _, err := s.t.TorrentClient.AddMagnet(magnet.String()); err != nil {
81+
return nil, err
82+
}
83+
}
7784
}
7885
if len(request.Items) == 1 {
7986
t, ok := s.t.TorrentClient.Torrent(infoHashes[0])
@@ -84,11 +91,7 @@ func (s *GrpcServer) Download(ctx context.Context, request *proto_downloader.Dow
8491
case <-ctx.Done():
8592
return nil, ctx.Err()
8693
case <-t.GotInfo():
87-
if !t.Complete.Bool() {
88-
t.DownloadAll()
89-
}
90-
mi := t.Metainfo()
91-
if err := CreateTorrentFileIfNotExists(s.snapshotDir, t.Info(), &mi); err != nil {
94+
if err := CreateTorrentFileIfNotExists(s.snapshotDir, t.Info(), mi); err != nil {
9295
return nil, err
9396
}
9497
}

0 commit comments

Comments
 (0)