This commit is contained in:
Alexey Kasyanchuk
2019-05-03 00:25:50 +03:00
parent e552b491a8
commit 356db94dff
7 changed files with 165 additions and 165 deletions

View File

@ -131,15 +131,15 @@ if (!gotTheLock) {
logT('app', 'closed because of second application')
app.exit(0);
} else {
app.on('second-instance', (event, commandLine, workingDirectory) => {
// Someone tried to run a second instance, we should focus our window.
logT('app', 'openned second application, just focus this one')
if (mainWindow) {
if (mainWindow.isMinimized())
mainWindow.restore();
mainWindow.focus();
}
})
app.on('second-instance', (event, commandLine, workingDirectory) => {
// Someone tried to run a second instance, we should focus our window.
logT('app', 'openned second application, just focus this one')
if (mainWindow) {
if (mainWindow.isMinimized())
mainWindow.restore();
mainWindow.focus();
}
})
}
// log autoupdate

View File

@ -336,7 +336,7 @@ class p2p {
server.close();
})
this.p2pStatus = 2
this.send('p2pStatus', this.p2pStatus)
this.send('p2pStatus', this.p2pStatus)
}
else
{
@ -349,7 +349,7 @@ class p2p {
this.connectToRelay(candidatePeer[0])
}
this.p2pStatus = 0
this.send('p2pStatus', this.p2pStatus)
this.send('p2pStatus', this.p2pStatus)
}
})
}
@ -430,7 +430,7 @@ class p2p {
logTE('relay', 'no port in relay request responce');
return;
}
logT('relay', 'try connecting to new relay', relayPeer.peerId)
let peers = {}
this.relaySocket = new JsonSocket(new net.Socket());
@ -441,15 +441,15 @@ class p2p {
this.send('p2pStatus', this.p2pStatus)
tryes = 3; // restore tryies bebause we connected
});
this.relaySocket.on('message', (data) => {
if(!data.id)
return
if(!peers[data.id]) {
if(data.close)
return
peers[data.id] = new JsonSocket(new net.Socket());
peers[data.id].on('message', (toPeer) => {
//logT('relay', 'client message to relay', data.id);
@ -466,12 +466,12 @@ class p2p {
logT('relay', 'peer disconnected');
return
}
//logT('relay', 'client message to my server', data.id);
peers[data.id].sendMessage(data.data)
}
});
this.relaySocket.on('close', () => {
logT('relay', 'relay client closed because server exit');
for(const id in peers) {
@ -480,14 +480,14 @@ class p2p {
peers = null
this.relaySocket = null
this.p2pStatus = 0
this.send('p2pStatus', this.p2pStatus)
this.send('p2pStatus', this.p2pStatus)
// try reconnect to new relay server
let candidatePeer = this.peersList().filter(peer => peer.relay && peer.relay.server && peer != relayPeer)
if(candidatePeer && candidatePeer.length > 0 && tryes > 0) {
logT('relay', 'reconnect to new relay, because old closed');
this.connectToRelay(candidatePeer[0], --tryes)
}
});
});
})
}
}
@ -603,7 +603,7 @@ class p2p {
data.relays.forEach(peer => this.add(peer, true))
}
}
// try connect to relay if needed
this.connectToRelay(address)

View File

@ -107,18 +107,18 @@ module.exports = function (send, recive, dataDirectory, version, env)
const sphinxSingle = await single().waitConnection()
let torrentsInfo = await sphinxSingle.query(`
SELECT
MAX(id) as maxid,
COUNT(*) as torrentscount,
SUM(files) as numfiles,
SUM(size) as filessize
FROM torrents
`);
SELECT
MAX(id) as maxid,
COUNT(*) as torrentscount,
SUM(files) as numfiles,
SUM(size) as filessize
FROM torrents
`);
let filesInfo = await sphinxSingle.query(`
SELECT
MAX(id) as maxid
FROM files
`);
SELECT
MAX(id) as maxid
FROM files
`);
if(torrentsInfo && torrentsInfo[0])
{
torrentsInfo = torrentsInfo[0]
@ -168,8 +168,8 @@ module.exports = function (send, recive, dataDirectory, version, env)
})
} else {
fs.readdirSync(__dirname + '/strategies').forEach((strategie) => {
this.trackers.push(new (require('./strategies/' + strategie))(args))
logT('tracker', 'loaded strategie', strategie)
this.trackers.push(new (require('./strategies/' + strategie))(args))
logT('tracker', 'loaded strategie', strategie)
})
}
}

View File

@ -4,60 +4,60 @@ const cheerio = require('cheerio')
module.exports = class Stragegie
{
get name() { return '1337x' }
get name() { return '1337x' }
async findHash(hash)
{
let html;
try {
html = await fetch(`https://1337x.to/srch?search=${hash}`)
} catch(err) {
return
}
if(!html)
return
html = await html.textConverted()
const $ = cheerio.load(html)
async findHash(hash)
{
let html;
try {
html = await fetch(`https://1337x.to/srch?search=${hash}`)
} catch(err) {
return
}
if(!html)
return
html = await html.textConverted()
const $ = cheerio.load(html)
this.href = $($('.table-list tr td a').get(1)).attr('href')
if(this.href)
this.id = this.href.match(/\/torrent\/([0-9]+)\//)[1];
this.href = $($('.table-list tr td a').get(1)).attr('href')
if(this.href)
this.id = this.href.match(/\/torrent\/([0-9]+)\//)[1];
return await this.parse();
}
return await this.parse();
}
async parse()
{
let html;
try {
html = await fetch('https://1337x.to' + this.href)
} catch(err) {
return
}
if(!html)
return
html = await html.textConverted()
const $ = cheerio.load(html)
const topicTitle = $('h1').text()
if(!topicTitle)
return
async parse()
{
let html;
try {
html = await fetch('https://1337x.to' + this.href)
} catch(err) {
return
}
if(!html)
return
html = await html.textConverted()
const $ = cheerio.load(html)
const topicTitle = $('h1').text()
if(!topicTitle)
return
let contentCategory;
try {
contentCategory = $('.torrent-category-detail .list li').first().find('span').text()
} catch(er) {}
let contentCategory;
try {
contentCategory = $('.torrent-category-detail .list li').first().find('span').text()
} catch(er) {}
let poster = $('.torrent-image img').attr('src') || $('#description img').attr('data-original');
if(poster)
poster = poster.replace(/^\/\//, 'https://');
let poster = $('.torrent-image img').attr('src') || $('#description img').attr('data-original');
if(poster)
poster = poster.replace(/^\/\//, 'https://');
return {
name: topicTitle.trim(),
poster,
description: $('#description').text(),
x1337ThreadId: parseInt(this.id),
x1337Href: this.href,
contentCategory
}
}
return {
name: topicTitle.trim(),
poster,
description: $('#description').text(),
x1337ThreadId: parseInt(this.id),
x1337Href: this.href,
contentCategory
}
}
}