fix(downloading): fix state on some torrent cases

This commit is contained in:
Alexey Kasyanchuk
2018-06-27 18:15:36 +03:00
parent 0d81364ca8
commit ea07872137
4 changed files with 102 additions and 61 deletions

View File

@ -576,12 +576,14 @@ module.exports = async ({
callback(true)
});
torrentClient._add = (torrentObject, savePath) =>
torrentClient._add = (torrentObject, savePath, callback) =>
{
const magnet = `magnet:?xt=urn:btih:${torrentObject.hash}`
console.log('download', magnet)
if(torrentClient.get(magnet)) {
console.log('aready added')
if(callback)
callback(false)
return
}
@ -596,7 +598,6 @@ module.exports = async ({
torrent.on('done', () => {
console.log('download done', torrent.infoHash)
delete torrentClientHashMap[torrent.infoHash]
send('downloadDone', torrent.infoHash)
})
@ -614,6 +615,9 @@ module.exports = async ({
timeRemaining: torrent.timeRemaining
})
})
if(callback)
callback(true)
}
recive('download', torrentClient._add);
@ -623,6 +627,7 @@ module.exports = async ({
const id = torrentClientHashMap[hash]
if(!id)
{
console.log('cant find torrent for removing', hash)
if(callback)
callback(false)
return