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

@ -447,6 +447,16 @@ const cleanupTorrents = (cleanTorrents = 1) => {
*/
}
const checkTorrent = (torrent) => {
if(config.filters.maxFiles > 0 && torrent.files > config.filters.maxFiles)
{
console.log('ignore', torrent.name, 'because files', torrent.files, '>', config.filters.maxFiles)
return false
}
return true
}
const insertTorrentToDB = (torrent) => {
if(!torrent)
return
@ -463,6 +473,11 @@ const insertTorrentToDB = (torrent) => {
delete torrent.contenttype;
}
if(!checkTorrent(torrent))
{
return
}
const { filesList } = torrent
delete torrent.filesList;
@ -533,6 +548,12 @@ const insertTorrentToDB = (torrent) => {
})
}
const removeTorrentFromDB = (torrent) => {
const {hash} = torrent
mysqlSingle.query('DELETE FROM torrents WHERE hash = ?', hash)
mysqlSingle.query('DELETE FROM files WHERE hash = ?', hash)
}
const updateTorrent = (metadata, infohash, rinfo) => {
console.log('finded torrent', metadata.info.name, ' and add to database');
@ -713,7 +734,9 @@ API({
spider,
upnp,
crypto,
insertTorrentToDB
insertTorrentToDB,
removeTorrentFromDB,
checkTorrent
})
if(config.indexer) {