feat(top): top over different time over all types #26

This commit is contained in:
Alexey Kasyanchuk
2018-05-14 12:32:50 +03:00
parent 80fea92cbb
commit 7ba5aab9a2
2 changed files with 99 additions and 57 deletions

View File

@ -435,29 +435,30 @@ module.exports = ({
const index = parseInt(navigation.index) || 0;
const limit = parseInt(navigation.limit) || 20;
const time = navigation.time
if(type && type.length > 0)
{
if(type == 'hours')
{
where = ' and `added` > ' + (Math.floor(Date.now() / 1000) - (60 * 60 * 24))
}
else if(type == 'week')
{
where = ' and `added` > ' + (Math.floor(Date.now() / 1000) - (60 * 60 * 24 * 7))
}
else if(type == 'month')
{
where = ' and `added` > ' + (Math.floor(Date.now() / 1000) - (60 * 60 * 24 * 30))
}
else
{
where += ' and contentType = ' + sphinx.escape(type) + ' ';
}
where += ' and contentType = ' + sphinx.escape(type) + ' ';
}
if(time)
{
if(time == 'hours')
{
where += ' and `added` > ' + (Math.floor(Date.now() / 1000) - (60 * 60 * 24))
}
else if(time == 'week')
{
where += ' and `added` > ' + (Math.floor(Date.now() / 1000) - (60 * 60 * 24 * 7))
}
else if(time == 'month')
{
where += ' and `added` > ' + (Math.floor(Date.now() / 1000) - (60 * 60 * 24 * 30))
}
}
const query = `SELECT * FROM torrents WHERE seeders > 0 and contentCategory != 'xxx' ${where} ORDER BY seeders DESC LIMIT ${index},${limit}`;
console.log(query)
if(topCache[query])
{
callback(topCache[query]);
@ -486,7 +487,7 @@ module.exports = ({
const peer = { address: socket.remoteAddress, port: socket.remotePort }
remote = remote.map(torrent => Object.assign(torrent, {peer}))
}
send('remoteTopTorrents', {torrents: remote, type})
send('remoteTopTorrents', {torrents: remote, type, time: navigation && navigation.time})
})
});