файл конфигурации
This commit is contained in:
parent
ab9c2eccbb
commit
4a2dcd7d36
24
config.js
Normal file
24
config.js
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
module.exports = {
|
||||||
|
indexer: true,
|
||||||
|
|
||||||
|
domain: 'ratsontheboat.org',
|
||||||
|
httpPort: 8095,
|
||||||
|
spiderPort: 4445,
|
||||||
|
udpTrackersPort: 4446,
|
||||||
|
|
||||||
|
sitemapMaxSize: 25000,
|
||||||
|
|
||||||
|
sphinx: {
|
||||||
|
host : 'localhost',
|
||||||
|
port : 9306,
|
||||||
|
connectionLimit: 30
|
||||||
|
},
|
||||||
|
|
||||||
|
mysql: {
|
||||||
|
host : 'localhost',
|
||||||
|
user : 'btsearch',
|
||||||
|
password : 'pirateal100x',
|
||||||
|
database : 'btsearch',
|
||||||
|
connectionLimit: 40
|
||||||
|
},
|
||||||
|
}
|
56
index.js
56
index.js
@ -1,3 +1,4 @@
|
|||||||
|
const config = require('./config');
|
||||||
const client = new (require('./lib/client'))
|
const client = new (require('./lib/client'))
|
||||||
const spider = new (require('./lib/spider'))(client)
|
const spider = new (require('./lib/spider'))(client)
|
||||||
const mysql = require('mysql');
|
const mysql = require('mysql');
|
||||||
@ -12,36 +13,21 @@ var phantomjs = require('phantomjs-prebuilt')
|
|||||||
|
|
||||||
const torrentTypeDetect = require('./lib/content');
|
const torrentTypeDetect = require('./lib/content');
|
||||||
|
|
||||||
const domain = 'ratsontheboat.org';
|
|
||||||
const http_port = 8095;
|
|
||||||
|
|
||||||
const mysqlSettings = {
|
|
||||||
host : 'localhost',
|
|
||||||
user : 'btsearch',
|
|
||||||
password : 'pirateal100x',
|
|
||||||
database : 'btsearch'
|
|
||||||
};
|
|
||||||
|
|
||||||
const sphinxSettings = {
|
|
||||||
host : 'localhost',
|
|
||||||
port : 9306
|
|
||||||
};
|
|
||||||
|
|
||||||
// Start server
|
// Start server
|
||||||
server.listen(http_port);
|
server.listen(config.httpPort);
|
||||||
|
|
||||||
let socketMysql = mysql.createPool({
|
let socketMysql = mysql.createPool({
|
||||||
connectionLimit: 40,
|
connectionLimit: config.mysql.connectionLimit,
|
||||||
host : mysqlSettings.host,
|
host : config.mysql.host,
|
||||||
user : mysqlSettings.user,
|
user : config.mysql.user,
|
||||||
password : mysqlSettings.password,
|
password : config.mysql.password,
|
||||||
database : mysqlSettings.database
|
database : config.mysql.database
|
||||||
});
|
});
|
||||||
|
|
||||||
let sphinx = mysql.createPool({
|
let sphinx = mysql.createPool({
|
||||||
connectionLimit: 30,
|
connectionLimit: config.sphinx.connectionLimit,
|
||||||
host : sphinxSettings.host,
|
host : config.sphinx.host,
|
||||||
port : sphinxSettings.port
|
port : config.sphinx.port
|
||||||
});
|
});
|
||||||
|
|
||||||
const udpTrackers = [
|
const udpTrackers = [
|
||||||
@ -65,7 +51,12 @@ const udpTrackers = [
|
|||||||
|
|
||||||
let listenerMysql;
|
let listenerMysql;
|
||||||
function handleListenerDisconnect() {
|
function handleListenerDisconnect() {
|
||||||
listenerMysql = mysql.createConnection(mysqlSettings);
|
listenerMysql = mysql.createConnection({
|
||||||
|
host : config.mysql.host,
|
||||||
|
user : config.mysql.user,
|
||||||
|
password : config.mysql.password,
|
||||||
|
database : config.mysql.database
|
||||||
|
});
|
||||||
|
|
||||||
listenerMysql.connect(function(mysqlError) {
|
listenerMysql.connect(function(mysqlError) {
|
||||||
if (mysqlError) {
|
if (mysqlError) {
|
||||||
@ -88,15 +79,14 @@ handleListenerDisconnect();
|
|||||||
|
|
||||||
app.use(express.static('build', {index: false}));
|
app.use(express.static('build', {index: false}));
|
||||||
|
|
||||||
const sitemapSize = 30000;
|
|
||||||
app.get('/sitemap.xml', function(req, res) {
|
app.get('/sitemap.xml', function(req, res) {
|
||||||
socketMysql.query('SELECT count(*) as cnt FROM `torrents` WHERE contentCategory != \'xxx\' OR contentCategory IS NULL', function (error, rows, fields) {
|
socketMysql.query('SELECT count(*) as cnt FROM `torrents` WHERE contentCategory != \'xxx\' OR contentCategory IS NULL', function (error, rows, fields) {
|
||||||
if(!rows) {
|
if(!rows) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let urls = []
|
let urls = []
|
||||||
for(let i = 0; i < Math.ceil(rows[0].cnt / sitemapSize); i++)
|
for(let i = 0; i < Math.ceil(rows[0].cnt / config.sitemapMaxSize); i++)
|
||||||
urls.push(`http://${domain}/sitemap${i+1}.xml`);
|
urls.push(`http://${config.domain}/sitemap${i+1}.xml`);
|
||||||
|
|
||||||
res.header('Content-Type', 'application/xml');
|
res.header('Content-Type', 'application/xml');
|
||||||
res.send( sm.buildSitemapIndex({
|
res.send( sm.buildSitemapIndex({
|
||||||
@ -109,14 +99,14 @@ app.get('/sitemap:id.xml', function(req, res) {
|
|||||||
if(req.params.id < 1)
|
if(req.params.id < 1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
let page = (req.params.id - 1) * sitemapSize
|
let page = (req.params.id - 1) * config.sitemapMaxSize
|
||||||
|
|
||||||
socketMysql.query('SELECT hash FROM `torrents` WHERE contentCategory != \'xxx\' OR contentCategory IS NULL LIMIT ?, ?', [page, sitemapSize], function (error, rows, fields) {
|
socketMysql.query('SELECT hash FROM `torrents` WHERE contentCategory != \'xxx\' OR contentCategory IS NULL LIMIT ?, ?', [page, config.sitemapMaxSize], function (error, rows, fields) {
|
||||||
if(!rows) {
|
if(!rows) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let sitemap = sm.createSitemap ({
|
let sitemap = sm.createSitemap ({
|
||||||
hostname: 'http://' + domain,
|
hostname: 'http://' + config.domain,
|
||||||
cacheTime: 600000
|
cacheTime: 600000
|
||||||
});
|
});
|
||||||
sitemap.add({url: '/'});
|
sitemap.add({url: '/'});
|
||||||
@ -138,7 +128,7 @@ app.get('*', function(req, res)
|
|||||||
{
|
{
|
||||||
if(typeof req.query['_escaped_fragment_'] != 'undefined')
|
if(typeof req.query['_escaped_fragment_'] != 'undefined')
|
||||||
{
|
{
|
||||||
let program = phantomjs.exec('phantom.js', 'http://' + domain + req.path)
|
let program = phantomjs.exec('phantom.js', 'http://' + config.domain + req.path)
|
||||||
let body = '';
|
let body = '';
|
||||||
program.stderr.pipe(process.stderr)
|
program.stderr.pipe(process.stderr)
|
||||||
program.stdout.on('data', (chunk) => {
|
program.stdout.on('data', (chunk) => {
|
||||||
@ -514,4 +504,4 @@ client.on('complete', function (metadata, infohash, rinfo) {
|
|||||||
|
|
||||||
// spider.on('nodes', (nodes)=>console.log('foundNodes'))
|
// spider.on('nodes', (nodes)=>console.log('foundNodes'))
|
||||||
|
|
||||||
spider.listen(4445)
|
spider.listen(config.spiderPort)
|
@ -1,5 +1,6 @@
|
|||||||
const dgram = require('dgram');
|
const dgram = require('dgram');
|
||||||
const server = dgram.createSocket("udp4")
|
const server = dgram.createSocket("udp4")
|
||||||
|
const config = require('../config');
|
||||||
|
|
||||||
const ACTION_CONNECT = 0
|
const ACTION_CONNECT = 0
|
||||||
const ACTION_ANNOUNCE = 1
|
const ACTION_ANNOUNCE = 1
|
||||||
@ -117,7 +118,7 @@ server.on("listening", function () {
|
|||||||
console.log("listening udp tracker respose on " + address.address + ":" + address.port);
|
console.log("listening udp tracker respose on " + address.address + ":" + address.port);
|
||||||
});
|
});
|
||||||
|
|
||||||
server.bind(4446);
|
server.bind(config.udpTrackersPort);
|
||||||
|
|
||||||
module.exports = getPeersStatistic;
|
module.exports = getPeersStatistic;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user