fix(content): basic adult filtration
This commit is contained in:
parent
81bd30c8a3
commit
aae2ddf458
5
package-lock.json
generated
5
package-lock.json
generated
@ -5029,6 +5029,11 @@
|
|||||||
"integrity": "sha1-AWLsLZNR9d3VmpICy6k1NmpyUIA=",
|
"integrity": "sha1-AWLsLZNR9d3VmpICy6k1NmpyUIA=",
|
||||||
"dev": true
|
"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": {
|
"component-bind": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/component-bind/-/component-bind-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/component-bind/-/component-bind-1.0.0.tgz",
|
||||||
|
@ -112,6 +112,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"bencode": "^1.0.0",
|
"bencode": "^1.0.0",
|
||||||
"bitfield": "^1.1.2",
|
"bitfield": "^1.1.2",
|
||||||
|
"compare-versions": "^3.1.0",
|
||||||
"debug": "^3.1.0",
|
"debug": "^3.1.0",
|
||||||
"diskusage": "^0.2.4",
|
"diskusage": "^0.2.4",
|
||||||
"electron-context-menu": "^0.9.1",
|
"electron-context-menu": "^0.9.1",
|
||||||
|
@ -249,7 +249,7 @@ const blockBadName = (torrent, name) => {
|
|||||||
if (XXX_BLOCK_WORDS.some(function(v) { return word == v; })) {
|
if (XXX_BLOCK_WORDS.some(function(v) { return word == v; })) {
|
||||||
torrent[ContentCategoryProp] = 'xxx';
|
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);
|
blockBadName(torrent, name);
|
||||||
// блокируем так по названию файлов
|
// блокируем так по названию файлов
|
||||||
if(torrent[ContentCategoryProp] != 'xxx')
|
if(torrent[ContentTypeProp] != 'bad')
|
||||||
{
|
{
|
||||||
files.some(({path}) => {
|
files.some(({path}) => {
|
||||||
let fileCheck = path.toLowerCase().split('.');
|
let fileCheck = path.toLowerCase().split('.');
|
||||||
@ -270,11 +270,8 @@ const detectSubCategory = (torrent, files, typesPriority, contentType) => {
|
|||||||
fileCheck = fileCheck.join('.');
|
fileCheck = fileCheck.join('.');
|
||||||
|
|
||||||
blockBadName(torrent, fileCheck);
|
blockBadName(torrent, fileCheck);
|
||||||
if(torrent[ContentCategoryProp] == 'xxx')
|
|
||||||
{
|
return torrent[ContentTypeProp] == 'bad';
|
||||||
console.log('marked torrent xxx because file ' + path);
|
|
||||||
}
|
|
||||||
return torrent[ContentCategoryProp] == 'xxx';
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
const ipaddr = require('ipaddr.js');
|
const ipaddr = require('ipaddr.js');
|
||||||
const forBigTable = require('./forBigTable')
|
const forBigTable = require('./forBigTable')
|
||||||
|
const compareVersions = require('compare-versions');
|
||||||
|
const getTorrent = require('./gettorrent')
|
||||||
|
|
||||||
module.exports = ({
|
module.exports = ({
|
||||||
sphinx,
|
sphinx,
|
||||||
@ -90,9 +92,16 @@ module.exports = ({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
delete options.peer;
|
delete options.peer;
|
||||||
peer.emit('torrent', {hash, options}, (data) => {
|
peer.emit('torrent', {hash, options}, (data, nil, address) => {
|
||||||
console.log('remote torrent result', hash)
|
console.log('remote torrent result', hash)
|
||||||
callback(data)
|
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)
|
if(data)
|
||||||
insertTorrentToDB(data, true) // copy torrent to our db
|
insertTorrentToDB(data, true) // copy torrent to our db
|
||||||
})
|
})
|
||||||
@ -141,15 +150,6 @@ module.exports = ({
|
|||||||
onTorrent(hash, options, (data) => callback(data))
|
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)
|
if(config.p2pReplication)
|
||||||
{
|
{
|
||||||
console.log('p2p replication enabled')
|
console.log('p2p replication enabled')
|
||||||
@ -190,10 +190,16 @@ module.exports = ({
|
|||||||
|
|
||||||
const getReplicationTorrents = (nextTimeout = 5000) => {
|
const getReplicationTorrents = (nextTimeout = 5000) => {
|
||||||
let gotTorrents = 0
|
let gotTorrents = 0
|
||||||
p2p.emit('randomTorrents', null, (torrents) => {
|
p2p.emit('randomTorrents', null, (torrents, nil, address) => {
|
||||||
if(!torrents || torrents.length == 0)
|
if(!torrents || torrents.length == 0)
|
||||||
return
|
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
|
gotTorrents += torrents.length
|
||||||
|
|
||||||
torrents.forEach((torrent) => {
|
torrents.forEach((torrent) => {
|
||||||
@ -705,7 +711,7 @@ module.exports = ({
|
|||||||
vote: action,
|
vote: action,
|
||||||
_index: `vote:${hash}`,
|
_index: `vote:${hash}`,
|
||||||
_temp: {
|
_temp: {
|
||||||
torrent: await getTorrent(hash)
|
torrent: await getTorrent(sphinx, hash)
|
||||||
}
|
}
|
||||||
}), 0)
|
}), 0)
|
||||||
good += isGood ? 1 : 0
|
good += isGood ? 1 : 0
|
||||||
|
@ -5,7 +5,12 @@ const url = require('url')
|
|||||||
const path = require('path')
|
const path = require('path')
|
||||||
const fs = require('fs')
|
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) => {
|
module.exports = async (callback, mainWindow, sphinxApp) => {
|
||||||
const sphinx = await single().waitConnection()
|
const sphinx = await single().waitConnection()
|
||||||
@ -144,6 +149,40 @@ module.exports = async (callback, mainWindow, sphinxApp) => {
|
|||||||
|
|
||||||
await setVersion(3)
|
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')
|
console.log('db patch done')
|
||||||
sphinx.destroy()
|
sphinx.destroy()
|
||||||
|
8
src/background/gettorrent.js
Normal file
8
src/background/gettorrent.js
Normal 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]
|
||||||
|
}
|
||||||
|
}
|
@ -47,7 +47,10 @@ class p2p {
|
|||||||
id: message.id,
|
id: message.id,
|
||||||
data
|
data
|
||||||
});
|
});
|
||||||
}, socket)
|
}, socket, {
|
||||||
|
version: message.version,
|
||||||
|
info: message.info
|
||||||
|
})
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
socket.protocolTimeout = setTimeout(() => socket._socket.destroy(), 7000)
|
socket.protocolTimeout = setTimeout(() => socket._socket.destroy(), 7000)
|
||||||
@ -216,7 +219,7 @@ class p2p {
|
|||||||
socket.on('message', (message) => {
|
socket.on('message', (message) => {
|
||||||
if(message.id && callbacks[message.id])
|
if(message.id && callbacks[message.id])
|
||||||
{
|
{
|
||||||
callbacks[message.id](message.data, socket);
|
callbacks[message.id](message.data, socket, address);
|
||||||
delete callbacks[message.id];
|
delete callbacks[message.id];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user