From cebf105691dffea3aad86fdf0eb0121448d4a09f Mon Sep 17 00:00:00 2001 From: Alexey Kasyanchuk Date: Sat, 18 Aug 2018 11:26:05 +0300 Subject: [PATCH] eslint --- src/app/torrent-page.js | 38 +++++++++++------------ src/app/torrent.js | 10 +++--- src/app/trackers-images.js | 22 ++++++------- src/background/directoryFilesRecursive.js | 36 ++++++++++----------- src/background/mysql.js | 2 +- src/background/portCheck.js | 14 ++++----- src/background/sphinx.js | 14 ++++----- src/background/spider.js | 36 ++++++++++----------- tests/seach.test.js | 32 +++++++++---------- 9 files changed, 102 insertions(+), 102 deletions(-) diff --git a/src/app/torrent-page.js b/src/app/torrent-page.js index dd183e8..472511a 100644 --- a/src/app/torrent-page.js +++ b/src/app/torrent-page.js @@ -25,14 +25,14 @@ let parseDescriptionText = (text) => { const text = /(.+?:)(.*)/.exec(item) return ( - - { - text ? {`${text[1]} `}{text[2]} : item - } -
-
+ + { + text ? {`${text[1]} `}{text[2]} : item + } +
+
) - }) + }) } let buildFilesTree = (filesList) => { @@ -203,10 +203,10 @@ export default class TorrentPage extends Page { } //this.forceUpdate(); // вызывается через searchingIndicator - // Получаем более новую статистику пира - if((Date.now() / 1000) - this.torrent.trackersChecked > 10 * 60) { + // Получаем более новую статистику пира + if((Date.now() / 1000) - this.torrent.trackersChecked > 10 * 60) { window.torrentSocket.emit('checkTrackers', this.torrent.hash); - } + } } }, () => { this.setState({ @@ -236,7 +236,7 @@ export default class TorrentPage extends Page { if(!this.torrent) return; - this.torrent = Object.assign(this.torrent, info); + this.torrent = Object.assign(this.torrent, info); this.forceUpdate(); } window.torrentSocket.on('trackerTorrentUpdate', this.trackerUpdate); @@ -376,7 +376,7 @@ export default class TorrentPage extends Page {
-
- { - this.torrent && this.torrent.info && this.torrent.info.description - && -
-
{parseDescriptionText(this.torrent.info.description)}
-
- } + { + this.torrent && this.torrent.info && this.torrent.info.description + && +
+
{parseDescriptionText(this.torrent.info.description)}
+
+ } diff --git a/src/app/torrent.js b/src/app/torrent.js index 049d67d..7b8c72e 100644 --- a/src/app/torrent.js +++ b/src/app/torrent.js @@ -251,7 +251,7 @@ export default class Torrent extends Component { { const torrent = this.props.torrent; if(!torrent) - return null // can try draw null torrent (for example on downloading not started) + return null // can try draw null torrent (for example on downloading not started) let torrentRating = -1 if(torrent.good > 0 || torrent.bad > 0) @@ -262,8 +262,8 @@ export default class Torrent extends Component { return (
- { const link = '/torrent/' + torrent.hash; @@ -358,8 +358,8 @@ export default class Torrent extends Component {
{this.state.downloadProgress && formatBytes(this.state.downloadProgress.downloadSpeed || 0, 0)}/s
}
- } - + } + } diff --git a/src/app/trackers-images.js b/src/app/trackers-images.js index e1874b3..691eba3 100644 --- a/src/app/trackers-images.js +++ b/src/app/trackers-images.js @@ -6,23 +6,23 @@ import NyaaIcon from './images/strategies/nyaa.jpg' export default (props) => { let className = '' if(props.className) - className += props.className - const {info} = props - if(!info) - return null + className += props.className + const {info} = props + if(!info) + return null return (
- { - info.trackers.includes('rutracker') + { + info.trackers.includes('rutracker') && - } - { - info.trackers.includes('nyaa') + } + { + info.trackers.includes('nyaa') && - } -
+ } + ) } \ No newline at end of file diff --git a/src/background/directoryFilesRecursive.js b/src/background/directoryFilesRecursive.js index 13dec06..9217e31 100644 --- a/src/background/directoryFilesRecursive.js +++ b/src/background/directoryFilesRecursive.js @@ -1,24 +1,24 @@ const fs = require('fs') function directoryFilesRecursive (directory, filesList = []) { - let files; - try { - files = fs.readdirSync(directory) - } catch(err) { - if(err.code !== 'ENOTDIR') - throw err - else - return [directory] // if file, return file - } - for (const file of files) { - const filePath = `${directory}/${file}` - if (fs.statSync(filePath).isDirectory()) { - directoryFilesRecursive(filePath, filesList) - } else { - filesList.push(filePath) - } - } - return filesList + let files; + try { + files = fs.readdirSync(directory) + } catch(err) { + if(err.code !== 'ENOTDIR') + throw err + else + return [directory] // if file, return file + } + for (const file of files) { + const filePath = `${directory}/${file}` + if (fs.statSync(filePath).isDirectory()) { + directoryFilesRecursive(filePath, filesList) + } else { + filesList.push(filePath) + } + } + return filesList } module.exports = directoryFilesRecursive diff --git a/src/background/mysql.js b/src/background/mysql.js index 47e4fd7..e072f5f 100644 --- a/src/background/mysql.js +++ b/src/background/mysql.js @@ -127,7 +127,7 @@ const expand = (sphinx) => { key: 'id' }, options) values = Object.assign({}, values) // copy - + let names = ''; let data = ''; const parseValues = (values) => { diff --git a/src/background/portCheck.js b/src/background/portCheck.js index 11f0a9b..35ebac3 100644 --- a/src/background/portCheck.js +++ b/src/background/portCheck.js @@ -1,11 +1,11 @@ const net = require('net') module.exports = (port, host = '127.0.0.1') => new Promise((resolve, reject) => { - const tester = net.createServer() - .once('error', err => (err.code === 'EADDRINUSE' ? resolve(false) : reject(err))) - .once('listening', () => tester.once('close', () => resolve(true)).close()) - .listen({ - host, - port - }) + const tester = net.createServer() + .once('error', err => (err.code === 'EADDRINUSE' ? resolve(false) : reject(err))) + .once('listening', () => tester.once('close', () => resolve(true)).close()) + .listen({ + host, + port + }) }) diff --git a/src/background/sphinx.js b/src/background/sphinx.js index fda78ba..8934e02 100644 --- a/src/background/sphinx.js +++ b/src/background/sphinx.js @@ -15,8 +15,8 @@ const portCheck = require('./portCheck') const findGoodPort = async (port, host) => { while (!(await portCheck(port, host))) { - port++ - logT('sphinx', 'port is busy, listen on', port) + port++ + logT('sphinx', 'port is busy, listen on', port) } return port } @@ -51,11 +51,11 @@ const writeSphinxConfig = async (path, dbPath) => { rt_attr_uint = completed rt_attr_timestamp = trackersChecked rt_attr_uint = good - rt_attr_uint = bad - rt_attr_json = info - - ngram_len = 1 - ngram_chars = U+3000..U+2FA1F + rt_attr_uint = bad + rt_attr_json = info + + ngram_len = 1 + ngram_chars = U+3000..U+2FA1F } index files diff --git a/src/background/spider.js b/src/background/spider.js index c696d2f..6650a7e 100644 --- a/src/background/spider.js +++ b/src/background/spider.js @@ -93,8 +93,8 @@ module.exports = function (send, recive, dataDirectory, version, env) p2p.info.torrents = (await sphinxSingle.query("SELECT COUNT(*) as cnt from torrents"))[0].cnt p2p.info.files = (await sphinxSingle.query("SELECT COUNT(*) as cnt from files"))[0].cnt const sphinxSingleAlternative = await single().waitConnection() - - + + class RemoteTrackers { constructor(sphinx) @@ -143,12 +143,12 @@ module.exports = function (send, recive, dataDirectory, version, env) obj.trackers = [...new Set(obj.trackers)] info = obj - } }).then(() => { + } }).then(() => { send('trackerTorrentUpdate', { hash, info }); - }) + }) }) } } @@ -670,21 +670,21 @@ module.exports = function (send, recive, dataDirectory, version, env) recive('dropTorrents', (pathTorrents) => { logT('drop', 'drop torrents and replicate from original torrent files') const torrents = _.flatten(pathTorrents.map(path => directoryFilesRecursive(path))) - .filter(path => mime.getType(path) == 'application/x-bittorrent') - .map(path => { - try { - return ({ - torrent: parseTorrent(fs.readFileSync(path)), - path - }) - } catch(err) { - logT('drop', 'error on parse torrent:', path) - } - }) - .filter(torrent => torrent) + .filter(path => mime.getType(path) == 'application/x-bittorrent') + .map(path => { + try { + return ({ + torrent: parseTorrent(fs.readFileSync(path)), + path + }) + } catch(err) { + logT('drop', 'error on parse torrent:', path) + } + }) + .filter(torrent => torrent) torrents.forEach(({torrent, path}) => { - insertMetadata(torrent, torrent.infoHashBuffer, {address: '127.0.0.1', port: 666}) - logT('drop', 'copied torrent to db:', path) + insertMetadata(torrent, torrent.infoHashBuffer, {address: '127.0.0.1', port: 666}) + logT('drop', 'copied torrent to db:', path) }) logT('drop', 'torrent finish adding to db') }) diff --git a/tests/seach.test.js b/tests/seach.test.js index bafcc9b..8c5d356 100644 --- a/tests/seach.test.js +++ b/tests/seach.test.js @@ -5,23 +5,23 @@ describe("search", function() { this.timeout(30000); it("dht seach", async function() { - this.timeout(45000); - const { app } = this - await app.client.waitForExist('#searchInput') - await app.client.$('#searchInput').setValue('1413ba1915affdc3de7e1a81d6fdc32ef19395c9') - await app.client.click('#search') - await app.client.waitForExist('.torrentRow .torrentName') - const value = await app.client.$('.torrentRow .torrentName').getText() - assert.equal(value, 'Roblox_setup.exe') + this.timeout(45000); + const { app } = this + await app.client.waitForExist('#searchInput') + await app.client.$('#searchInput').setValue('1413ba1915affdc3de7e1a81d6fdc32ef19395c9') + await app.client.click('#search') + await app.client.waitForExist('.torrentRow .torrentName') + const value = await app.client.$('.torrentRow .torrentName').getText() + assert.equal(value, 'Roblox_setup.exe') }) it("sphinx search", async function() { - const { app } = this - await app.client.$('#searchInput').setValue('Roblox_setup') - await app.client.click('#search') - await app.client.waitForExist('.torrentRow .torrentName') - const results = (await app.client.$$('.torrentRow .torrentName')).length - assert(results >= 1, 'default search on Roblox must return Roblox_setup record') + const { app } = this + await app.client.$('#searchInput').setValue('Roblox_setup') + await app.client.click('#search') + await app.client.waitForExist('.torrentRow .torrentName') + const results = (await app.client.$$('.torrentRow .torrentName')).length + assert(results >= 1, 'default search on Roblox must return Roblox_setup record') }) it("sphinx particial search", async function() { @@ -31,9 +31,9 @@ describe("search", function() { await app.client.waitForExist('.torrentRow .torrentName') const results = (await app.client.$$('.torrentRow .torrentName')).length assert(results >= 1, 'particial word search must find string') - }) + }) - it("magnet search", async function() { + it("magnet search", async function() { const { app } = this await app.client.$('#searchInput').setValue('magnet:?xt=urn:btih:1413ba1915affdc3de7e1a81d6fdc32ef19395c9') await app.client.click('#search')