Prevent duplicates

This commit is contained in:
Ben Sarmiento
2024-05-25 01:24:24 +02:00
parent 442030c89d
commit 0a086d7a14
2 changed files with 23 additions and 9 deletions

View File

@@ -371,6 +371,8 @@ func (t *TorrentManager) redownloadTorrent(torrent *Torrent, selection []string)
}
// redownload torrent
var newTorrentID string
prevState := t.latestState
resp, err := t.api.AddMagnetHash(torrent.Hash)
if err != nil {
if strings.Contains(err.Error(), "infringing") {
@@ -386,10 +388,20 @@ func (t *TorrentManager) redownloadTorrent(torrent *Torrent, selection []string)
} else if strings.Contains(err.Error(), "allowed") {
t.markAsUnfixable(torrent, "torrent not allowed")
}
return nil, fmt.Errorf("cannot add magnet of torrent %s (hash=%s): %v", t.GetKey(torrent), torrent.Hash, err)
if strings.Contains(err.Error(), "timeout") {
newState := t.getCurrentState()
if prevState.Eq(newState) {
return t.redownloadTorrent(torrent, selection)
}
newTorrentID = t.latestState.FirstTorrentId
} else {
return nil, fmt.Errorf("cannot add magnet of torrent %s (hash=%s): %v", t.GetKey(torrent), torrent.Hash, err)
}
}
newTorrentID := resp.ID
if resp != nil {
newTorrentID = resp.ID
}
time.Sleep(2 * time.Second)