diff --git a/src/background/api.js b/src/background/api.js index f9b1703..0cd03e0 100644 --- a/src/background/api.js +++ b/src/background/api.js @@ -56,7 +56,7 @@ module.exports = async ({ downloaded: download.downloaded, progress: download.progress, downloadSpeed: download.downloadSpeed, - + removeOnDone: download.removeOnDone, paused: torrent.paused || torrent._paused } @@ -79,10 +79,10 @@ module.exports = async ({ return torrents } - const mergeTorrentsWithDownloadsFn = (Fn, copy) => (...args) => { + const mergeTorrentsWithDownloadsFn = (Fn, copy) => (...args) => { const callback = args[args.length - 2] const rest = args.slice(0, -2) - Fn(...rest, (data) => callback(mergeTorrentsWithDownloads(data, copy)), args[args.length - 1]) + Fn(...rest, (data) => callback(mergeTorrentsWithDownloads(data, copy)), args[args.length - 1]) } const downloadFilesList = (torrent) => torrent.files.map((file, index) => ({ @@ -215,7 +215,7 @@ module.exports = async ({ p2p.on('randomTorrents', (nil, callback) => { if(typeof callback != 'function') return; - + const cpu = cpuUsage() const limit = Math.max(1, 5 - (cpu / 20) | 0) @@ -224,19 +224,19 @@ module.exports = async ({ callback(undefined) return; } - + let hashes = {} for(const torrent of torrents) { delete torrent.id hashes[torrent.hash] = torrent } - + const inSql = Object.keys(hashes).map(hash => sphinx.escape(hash)).join(','); sphinxSingle.query(`SELECT * FROM files WHERE hash IN(${inSql})`, (error, files) => { for(const file of files) hashes[file.hash].filesList = parseTorrentFiles(file); - + callback(Object.values(hashes)) }) }) @@ -347,7 +347,7 @@ module.exports = async ({ { logT('search', 'get torrent via infohash with dht') // 3 try to get torrent from metadata - const getTorrentMetadata = (tryCount = 4) => { + const getTorrentMetadata = (tryCount = 8) => { if(tryCount <= 0) { logT('search', 'dht NOT found anything with dht', text); return @@ -356,7 +356,7 @@ module.exports = async ({ dhtCheckTimeout = setTimeout(() => { lock = true getTorrentMetadata(--tryCount) - }, 8000); + }, 16000); torrentClient.getMetadata(text, (torrent) => { if(lock) { logT('search', 'this dht response not actual for', text); @@ -455,7 +455,7 @@ module.exports = async ({ for(const torrent of torrents) { search[torrent.hash] = Object.assign(baseRowData(torrent), search[torrent.hash]) - + // temporary ignore adult content in search (workaroud) if(safeSearch && search[torrent.hash].contentCategory == 'xxx') delete search[torrent.hash] @@ -531,7 +531,7 @@ module.exports = async ({ where += ' and `added` > ' + (Math.floor(Date.now() / 1000) - (60 * 60 * 24 * 30)) } } - + const query = `SELECT * FROM torrents WHERE seeders > 0 and contentCategory != ${torrentCategoryId('xxx')} ${where} ORDER BY seeders DESC LIMIT ${index},${limit}`; if(topCache[query]) { @@ -543,7 +543,7 @@ module.exports = async ({ callback(undefined) return; } - + rows = rows.map((row) => baseRowData(row)); topCache[query] = rows; callback(rows); @@ -641,7 +641,7 @@ module.exports = async ({ delete copyConfig['load']; delete copyConfig['reload']; send('configChanged', copyConfig) - + if(typeof callback === 'function') callback(true) }); @@ -697,7 +697,7 @@ module.exports = async ({ send('filesReady', torrent.infoHash, downloadFilesList(torrent)) }) - torrent.on('done', () => { + torrent.on('done', () => { logT('downloader', 'download done', torrent.infoHash) progress(0) // update progress // remove torrent if marked @@ -709,7 +709,7 @@ module.exports = async ({ logT('downloader', 'download removing error', err) return } - + delete torrentClientHashMap[torrent.infoHash] send('downloadDone', torrent.infoHash) }) @@ -793,10 +793,10 @@ module.exports = async ({ } torrent.updateFilesSelection() } - + torrent.updateFilesSelection = () => { torrent.deselect(0, torrent.pieces.length - 1, false) - + for(const file of torrent.files) { const {selected} = file @@ -825,7 +825,7 @@ module.exports = async ({ logT('downloader', 'cant find torrent for removing', hash) return } - + const torrent = torrentClient.get(id) if(!torrent) { logT('downloader', 'no torrent for update founded') @@ -913,7 +913,7 @@ module.exports = async ({ downloaded: torrent.downloaded, progress: torrent.progress, downloadSpeed: torrent.downloadSpeed, - + removeOnDone: torrent.removeOnDone, paused: torrent.paused || torrent._paused }))) @@ -1018,11 +1018,11 @@ module.exports = async ({ // store torrent to feed await feed.load() - Object.defineProperty(p2p.info, 'feed', { + Object.defineProperty(p2p.info, 'feed', { enumerable: true, get: () => feed.size() }); - Object.defineProperty(p2p.info, 'feedDate', { + Object.defineProperty(p2p.info, 'feedDate', { enumerable: true, get: () => feed.feedDate }); @@ -1032,9 +1032,9 @@ module.exports = async ({ if(!temp || !temp.torrent) return - + const { torrent } = temp - + if(torrent.hash !== record.torrentHash) return @@ -1053,7 +1053,7 @@ module.exports = async ({ // update feed only on some good info if(torrent.good < 1) return - + feed.add(torrent) send('feedUpdate', { feed: feed.feed @@ -1083,7 +1083,7 @@ module.exports = async ({ peer.emit('feed', null, (remoteFeed) => { if(!remoteFeed) return - + if(Array.isArray(remoteFeed) || !remoteFeed.feed) return // old version call @@ -1091,7 +1091,7 @@ module.exports = async ({ logT('feed', 'remote feed have more torrent that needed: ', remoteFeed.feed.length, ' > ', feed.max); remoteFeed.feed = remoteFeed.feed.slice(0, feed.max); } - + if(remoteFeed.feed.length > feed.size() || (remoteFeed.feed.length == feed.size() && remoteFeed.feedDate > feed.feedDate)) { logT('feed', 'replace our feed with remote feed') @@ -1107,5 +1107,5 @@ module.exports = async ({ } } }) - -} \ No newline at end of file + +}