feat(filter): torrents filters (basic maxFiles filter)

This commit is contained in:
Alexey Kasyanchuk
2018-04-01 22:36:30 +03:00
parent 534999d1cb
commit 5348d1f88f
7 changed files with 264 additions and 2 deletions

View File

@ -11,7 +11,9 @@ module.exports = ({
spider,
upnp,
crypto,
insertTorrentToDB
insertTorrentToDB,
removeTorrentFromDB,
checkTorrent
}) => {
let torrentClientHashMap = {}
@ -601,6 +603,44 @@ module.exports = ({
})))
})
recive('removeTorrents', (checkOnly = true, callback) =>
{
console.log('checktorrents call')
const toRemove = []
const done = () => {
console.log('torrents to remove founded', toRemove.length)
if(checkOnly)
{
callback(toRemove.length)
return
}
toRemove.forEach(torrent => removeTorrentFromDB(torrent))
callback(toRemove.length)
console.log('removed torrents by filter:', toRemove.length)
}
const checker = (index = 0) => {
sphinx.query(`SELECT * FROM torrents LIMIT ${index},50000`, (err, torrents) => {
if(err || torrents.length == 0)
{
done()
return
}
torrents.forEach((torrent) => {
if(!checkTorrent(torrent))
toRemove.push(torrent)
})
checker(index + torrents.length)
});
}
checker()
})
let socketIPV4 = () => {
let ip = socket.request.connection.remoteAddress;
if (ipaddr.IPv4.isValid(ip)) {