This commit is contained in:
Alexey Kasyanchuk
2018-08-18 11:26:05 +03:00
parent 0cd43d674d
commit cebf105691
9 changed files with 102 additions and 102 deletions

View File

@ -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

View File

@ -127,7 +127,7 @@ const expand = (sphinx) => {
key: 'id'
}, options)
values = Object.assign({}, values) // copy
let names = '';
let data = '';
const parseValues = (values) => {

View File

@ -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
})
})

View File

@ -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

View File

@ -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')
})