From 619b3ccd32f12e716d8261f9a2a011b9cce3affa Mon Sep 17 00:00:00 2001 From: Alexey Kasyanchuk Date: Thu, 18 Feb 2021 19:33:31 +0300 Subject: [PATCH] fix(search): double search on DHT --- src/background/api.js | 17 +++++++++++++++++ tests/download.test.js | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/background/api.js b/src/background/api.js index c1e27d0..ebc6491 100644 --- a/src/background/api.js +++ b/src/background/api.js @@ -339,7 +339,24 @@ module.exports = async ({ if(rows.length === 0 && isSHA1 && !isP2P) // trying to get via dht { logT('search', 'get torrent via infohash with dht') + // double check torrent magnet + let secondTry = false; + const doubleCheckTimeout = setTimeout(() => { + secondTry = true; + logT('search', 'second try search by dht') + torrentClient.getMetadata(text, (torrent) => { + logT('search', 'dht search found something') + searchList.push(baseRowData(torrent)); + callback(searchList); + }) + }, 8000) torrentClient.getMetadata(text, (torrent) => { + clearTimeout(doubleCheckTimeout); + if(secondTry) { + logT('search', 'ignore search dht resopond because of second try') + return + } + logT('search', 'dht search found something') searchList.push(baseRowData(torrent)); callback(searchList); }) diff --git a/tests/download.test.js b/tests/download.test.js index b686a2b..7b98592 100644 --- a/tests/download.test.js +++ b/tests/download.test.js @@ -44,7 +44,7 @@ describe("download", function() { let progress = parseInt(await (await app.client.$('.torrentRow .progressDownloading')).getText()); console.log('download progress', progress, '%'); // cancel in progress button must be exists - if (progress < 90) { + if (progress < 50) { console.log('testing buttons') assert(await (await app.client.$('.torrentRow .deleteDownloadBeforeFinish')).isExisting()); assert(await (await app.client.$('.torrentRow .pauseTorrent')).isExisting());