feat(trackers): basic trackers integration
This commit is contained in:
parent
cff0f11c79
commit
317cfdd3fb
@ -24,7 +24,8 @@ module.exports = async ({
|
|||||||
checkTorrent,
|
checkTorrent,
|
||||||
setupTorrentRecord,
|
setupTorrentRecord,
|
||||||
p2pStore,
|
p2pStore,
|
||||||
feed
|
feed,
|
||||||
|
remoteTrackers
|
||||||
}) => {
|
}) => {
|
||||||
let torrentClientHashMap = {}
|
let torrentClientHashMap = {}
|
||||||
|
|
||||||
|
@ -155,7 +155,7 @@ const expand = (sphinx) => {
|
|||||||
queryCall(`SELECT * from ${table} WHERE \`${key}\` = ${sphinx.escape(values[key])}`, (err, row) => {
|
queryCall(`SELECT * from ${table} WHERE \`${key}\` = ${sphinx.escape(values[key])}`, (err, row) => {
|
||||||
if(err || row.length == 0)
|
if(err || row.length == 0)
|
||||||
{
|
{
|
||||||
logTE('sql', 'error on sql replace request', row)
|
logTE('sql', 'error on sql replace request', err)
|
||||||
resolve(undefined)
|
resolve(undefined)
|
||||||
callback(undefined)
|
callback(undefined)
|
||||||
return
|
return
|
||||||
|
@ -52,6 +52,7 @@ const writeSphinxConfig = async (path, dbPath) => {
|
|||||||
rt_attr_timestamp = trackersChecked
|
rt_attr_timestamp = trackersChecked
|
||||||
rt_attr_uint = good
|
rt_attr_uint = good
|
||||||
rt_attr_uint = bad
|
rt_attr_uint = bad
|
||||||
|
rt_attr_json = info
|
||||||
|
|
||||||
ngram_len = 1
|
ngram_len = 1
|
||||||
ngram_chars = U+3000..U+2FA1F
|
ngram_chars = U+3000..U+2FA1F
|
||||||
|
@ -39,6 +39,11 @@ const mime = require('mime');
|
|||||||
//server.listen(config.httpPort);
|
//server.listen(config.httpPort);
|
||||||
//console.log('Listening web server on', config.httpPort, 'port')
|
//console.log('Listening web server on', config.httpPort, 'port')
|
||||||
|
|
||||||
|
|
||||||
|
const Rutracker = require('./strategies/rutracker')
|
||||||
|
const Nyaa = require('./strategies/nyaa')
|
||||||
|
|
||||||
|
|
||||||
module.exports = function (send, recive, dataDirectory, version, env)
|
module.exports = function (send, recive, dataDirectory, version, env)
|
||||||
{
|
{
|
||||||
this.initialized = (async () =>
|
this.initialized = (async () =>
|
||||||
@ -84,7 +89,38 @@ module.exports = function (send, recive, dataDirectory, version, env)
|
|||||||
p2p.info.torrents = (await sphinxSingle.query("SELECT COUNT(*) as cnt from torrents"))[0].cnt
|
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
|
p2p.info.files = (await sphinxSingle.query("SELECT COUNT(*) as cnt from files"))[0].cnt
|
||||||
const sphinxSingleAlternative = await single().waitConnection()
|
const sphinxSingleAlternative = await single().waitConnection()
|
||||||
|
|
||||||
|
|
||||||
|
class RemoteTrackers
|
||||||
|
{
|
||||||
|
constructor(sphinx)
|
||||||
|
{
|
||||||
|
this.sphinx = sphinx
|
||||||
|
this.trackers = [
|
||||||
|
new Rutracker,
|
||||||
|
new Nyaa
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
findHash(hash, callback)
|
||||||
|
{
|
||||||
|
for(const tracker of this.trackers)
|
||||||
|
if(tracker.findHash)
|
||||||
|
tracker.findHash(hash).then(data => callback(tracker.name(), data))
|
||||||
|
}
|
||||||
|
|
||||||
|
update({hash, name})
|
||||||
|
{
|
||||||
|
this.findHash(hash, (tracker, data) => {
|
||||||
|
if(!data)
|
||||||
|
return
|
||||||
|
|
||||||
|
logT('tracker', 'found', name, 'on', tracker)
|
||||||
|
this.sphinx.replaceValues('torrents', {hash, info: data}, true, 'hash')
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
const remoteTrackers = new RemoteTrackers(sphinxSingle)
|
||||||
|
|
||||||
// start
|
// start
|
||||||
function baseRowData(row)
|
function baseRowData(row)
|
||||||
@ -462,6 +498,7 @@ module.exports = function (send, recive, dataDirectory, version, env)
|
|||||||
contentCategory: torrent.contentCategory,
|
contentCategory: torrent.contentCategory,
|
||||||
});
|
});
|
||||||
updateTorrentTrackers(torrent.hash);
|
updateTorrentTrackers(torrent.hash);
|
||||||
|
remoteTrackers.update(torrent)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -729,7 +766,8 @@ module.exports = function (send, recive, dataDirectory, version, env)
|
|||||||
checkTorrent,
|
checkTorrent,
|
||||||
setupTorrentRecord,
|
setupTorrentRecord,
|
||||||
p2pStore,
|
p2pStore,
|
||||||
feed
|
feed,
|
||||||
|
remoteTrackers
|
||||||
})
|
})
|
||||||
|
|
||||||
if(config.indexer) {
|
if(config.indexer) {
|
||||||
|
@ -4,6 +4,8 @@ const cheerio = require('cheerio')
|
|||||||
|
|
||||||
module.exports = class Nyaa
|
module.exports = class Nyaa
|
||||||
{
|
{
|
||||||
|
name() { return 'nyaa' }
|
||||||
|
|
||||||
async findHash(hash)
|
async findHash(hash)
|
||||||
{
|
{
|
||||||
this.hash = hash
|
this.hash = hash
|
||||||
|
@ -4,6 +4,8 @@ const cheerio = require('cheerio')
|
|||||||
|
|
||||||
module.exports = class Rutracker
|
module.exports = class Rutracker
|
||||||
{
|
{
|
||||||
|
name() { return 'rutracker' }
|
||||||
|
|
||||||
async findHash(hash)
|
async findHash(hash)
|
||||||
{
|
{
|
||||||
this.hash = hash
|
this.hash = hash
|
||||||
|
Loading…
Reference in New Issue
Block a user