fix(content): basic adult filtration

This commit is contained in:
Alexey Kasyanchuk 2018-04-26 10:13:41 +03:00
parent 81bd30c8a3
commit aae2ddf458
7 changed files with 81 additions and 22 deletions

5
package-lock.json generated
View File

@ -5029,6 +5029,11 @@
"integrity": "sha1-AWLsLZNR9d3VmpICy6k1NmpyUIA=",
"dev": true
},
"compare-versions": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/compare-versions/-/compare-versions-3.1.0.tgz",
"integrity": "sha512-4hAxDSBypT/yp2ySFD346So6Ragw5xmBn/e/agIGl3bZr6DLUqnoRZPusxKrXdYRZpgexO9daejmIenlq/wrIQ=="
},
"component-bind": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/component-bind/-/component-bind-1.0.0.tgz",

View File

@ -112,6 +112,7 @@
"dependencies": {
"bencode": "^1.0.0",
"bitfield": "^1.1.2",
"compare-versions": "^3.1.0",
"debug": "^3.1.0",
"diskusage": "^0.2.4",
"electron-context-menu": "^0.9.1",

View File

@ -249,7 +249,7 @@ const blockBadName = (torrent, name) => {
if (XXX_BLOCK_WORDS.some(function(v) { return word == v; })) {
torrent[ContentCategoryProp] = 'xxx';
}
return torrent[ContentCategoryProp] == 'xxx' || torrent[ContentTypeProp] == 'bad';
return torrent[ContentTypeProp] == 'bad'; // stop only if marked as bad, otherwise check all
})
}
@ -261,7 +261,7 @@ const detectSubCategory = (torrent, files, typesPriority, contentType) => {
{
blockBadName(torrent, name);
// блокируем так по названию файлов
if(torrent[ContentCategoryProp] != 'xxx')
if(torrent[ContentTypeProp] != 'bad')
{
files.some(({path}) => {
let fileCheck = path.toLowerCase().split('.');
@ -270,11 +270,8 @@ const detectSubCategory = (torrent, files, typesPriority, contentType) => {
fileCheck = fileCheck.join('.');
blockBadName(torrent, fileCheck);
if(torrent[ContentCategoryProp] == 'xxx')
{
console.log('marked torrent xxx because file ' + path);
}
return torrent[ContentCategoryProp] == 'xxx';
return torrent[ContentTypeProp] == 'bad';
})
}
}

View File

@ -1,5 +1,7 @@
const ipaddr = require('ipaddr.js');
const forBigTable = require('./forBigTable')
const compareVersions = require('compare-versions');
const getTorrent = require('./gettorrent')
module.exports = ({
sphinx,
@ -90,9 +92,16 @@ module.exports = ({
return;
}
delete options.peer;
peer.emit('torrent', {hash, options}, (data) => {
peer.emit('torrent', {hash, options}, (data, nil, address) => {
console.log('remote torrent result', hash)
callback(data)
if(compareVersions(address.version, '0.19.0') < 0)
{
console.log('replication selected torrent now works only with 0.19.0 version, ignore this torrent')
return
}
if(data)
insertTorrentToDB(data, true) // copy torrent to our db
})
@ -141,15 +150,6 @@ module.exports = ({
onTorrent(hash, options, (data) => callback(data))
})
const getTorrent = async (hash) => {
let torrent = await sphinx.query(`SELECT * FROM torrents WHERE hash = '${hash}'`)
if(torrent && torrent.length > 0)
{
torrent[0].filesList = (await sphinx.query(`SELECT * FROM files WHERE hash = '${hash}'`)) || []
return torrent[0]
}
}
if(config.p2pReplication)
{
console.log('p2p replication enabled')
@ -190,10 +190,16 @@ module.exports = ({
const getReplicationTorrents = (nextTimeout = 5000) => {
let gotTorrents = 0
p2p.emit('randomTorrents', null, (torrents) => {
p2p.emit('randomTorrents', null, (torrents, nil, address) => {
if(!torrents || torrents.length == 0)
return
if(compareVersions(address.version, '0.19.0') < 0)
{
console.log('replication now works only with 0.19.0 version, ignore this torrent')
return
}
gotTorrents += torrents.length
torrents.forEach((torrent) => {
@ -705,7 +711,7 @@ module.exports = ({
vote: action,
_index: `vote:${hash}`,
_temp: {
torrent: await getTorrent(hash)
torrent: await getTorrent(sphinx, hash)
}
}), 0)
good += isGood ? 1 : 0

View File

@ -5,7 +5,12 @@ const url = require('url')
const path = require('path')
const fs = require('fs')
const currentVersion = 3
const {torrentTypeDetect} = require('../app/content');
const getTorrent = require('./gettorrent')
const currentVersion = 4
module.exports = async (callback, mainWindow, sphinxApp) => {
const sphinx = await single().waitConnection()
@ -144,6 +149,40 @@ module.exports = async (callback, mainWindow, sphinxApp) => {
await setVersion(3)
}
case 3:
{
openPatchWindow()
// block xxx
let bad = 0
let i = 1
const torrents = (await sphinx.query("SELECT COUNT(*) AS c FROM torrents"))[0].c
await forBigTable(sphinx, 'torrents', async (torrent) => {
console.log('update index', torrent.id, torrent.name, '[', i, 'of', torrents, '] - delete:', bad)
if(patchWindow)
patchWindow.webContents.send('reindex', {field: torrent.name, index: i++, all: torrents, torrent: true})
if(torrent.contentcategory == 'xxx')
{
delete torrent.contentcategory
delete torrent.contenttype
torrent = await getTorrent(sphinx, null, torrent) // get files
torrentTypeDetect(torrent, torrent.filesList)
if(torrent.contentType == 'bad')
{
console.log('remove bad torrent', torrent.name)
bad++
await sphinx.query(`DELETE FROM torrents WHERE hash = '${torrent.hash}'`)
await sphinx.query(`DELETE FROM files WHERE hash = '${torrent.hash}'`)
}
}
})
console.log('removed', bad, 'torrents')
await setVersion(4)
}
}
console.log('db patch done')
sphinx.destroy()

View File

@ -0,0 +1,8 @@
module.exports = async (sphinx, hash, torrent) => {
torrent = (torrent && [torrent]) || await sphinx.query(`SELECT * FROM torrents WHERE hash = '${hash}'`)
if(torrent && torrent.length > 0)
{
torrent[0].filesList = (await sphinx.query(`SELECT * FROM files WHERE hash = '${torrent[0].hash}'`)) || []
return torrent[0]
}
}

View File

@ -47,7 +47,10 @@ class p2p {
id: message.id,
data
});
}, socket)
}, socket, {
version: message.version,
info: message.info
})
}
});
socket.protocolTimeout = setTimeout(() => socket._socket.destroy(), 7000)
@ -216,7 +219,7 @@ class p2p {
socket.on('message', (message) => {
if(message.id && callbacks[message.id])
{
callbacks[message.id](message.data, socket);
callbacks[message.id](message.data, socket, address);
delete callbacks[message.id];
}
});