From 56da04ecd1e638bdf0430c6bd589d6b1715f7c3a Mon Sep 17 00:00:00 2001 From: Alexey Kasyanchuk Date: Sun, 15 Jan 2017 17:48:54 +0300 Subject: [PATCH] =?UTF-8?q?=D1=80=D0=B0=D0=B7=D0=B1=D0=B8=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BA=D0=B0=D1=80=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index a96fc32..09e7160 100644 --- a/index.js +++ b/index.js @@ -88,8 +88,30 @@ handleListenerDisconnect(); app.use(express.static('build', {index: false})); +const sitemapSize = 30000; app.get('/sitemap.xml', function(req, res) { - socketMysql.query('SELECT hash FROM `torrents`', function (error, rows, fields) { + socketMysql.query('SELECT count(*) as cnt FROM `torrents`', function (error, rows, fields) { + if(!rows) { + return; + } + let urls = [] + for(let i = 0; i < Math.ceil(rows[0].cnt / sitemapSize); i++) + urls.push(`http://${domain}/sitemap${i+1}.xml`); + + res.header('Content-Type', 'application/xml'); + res.send( sm.buildSitemapIndex({ + urls + })); + }); +}); + +app.get('/sitemap:id.xml', function(req, res) { + if(req.params.id < 1) + return; + + let page = (req.params.id - 1) * sitemapSize + + socketMysql.query('SELECT hash FROM `torrents` LIMIT ?, ?', [page, sitemapSize], function (error, rows, fields) { if(!rows) { return; } @@ -111,6 +133,7 @@ app.get('/sitemap.xml', function(req, res) { }); }); + app.get('*', function(req, res) { if(typeof req.query['_escaped_fragment_'] != 'undefined') @@ -477,4 +500,4 @@ client.on('complete', function (metadata, infohash, rinfo) { // spider.on('nodes', (nodes)=>console.log('foundNodes')) -spider.listen(4445) \ No newline at end of file +//spider.listen(4445) \ No newline at end of file