Skip to content

Commit

Permalink
fix(download): fix search for double download cases
Browse files Browse the repository at this point in the history
  • Loading branch information
DEgITx committed Nov 7, 2019
1 parent e163547 commit 656f8f7
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/background/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,19 @@ module.exports = async ({
torrentClientHashMap[torrent.infoHash] = magnet
torrent.torrentObject = torrentObject

torrent.secondTry = setTimeout(() => {
logT('downloader', 'second try to find hash', torrent.infoHash)
torrentClient.remove(magnet, (err) => {
if(err)
{
logTE('downloader', 'cant remove torrent for second try', torrent.infoHash)
return
}
delete torrentClientHashMap[torrentObject.hash];
torrentClient._add(torrentObject, savePath, callback)
})
}, 8000);

const progress = (bytes) => {
send('downloadProgress', torrent.infoHash, {
received: bytes,
Expand All @@ -642,6 +655,7 @@ module.exports = async ({
torrent.on('ready', () => {
logT('downloader', 'start downloading', torrent.infoHash, 'to', torrent.path)
send('downloading', torrent.infoHash)
clearTimeout(torrent.secondTry);
progress(0) // immediately display progress
if(torrent._paused)
{
Expand Down Expand Up @@ -816,7 +830,7 @@ module.exports = async ({
callback(false)
return
}

clearTimeout(torrentClient.get(id).secondTry)
torrentClient.remove(id, (err) => {
if(err)
{
Expand Down

0 comments on commit 656f8f7

Please sign in to comment.