небольшие исправления

This commit is contained in:
Alexey Kasyanchuk
2017-01-03 05:44:24 +03:00
parent ed7a3dc685
commit c13534fe68
3 changed files with 27 additions and 5 deletions

View File

@ -91,6 +91,9 @@ io.on('connection', function(socket)
socket.on('recentTorrents', function(callback)
{
if(typeof callback != 'function')
return;
socketMysql.query('SELECT * FROM `torrents` ORDER BY added DESC LIMIT 0,10', function (error, rows, fields) {
let torrents = [];
rows.forEach((row) => {
@ -103,6 +106,9 @@ io.on('connection', function(socket)
socket.on('statistic', function(callback)
{
if(typeof callback != 'function')
return;
let stats = {};
socketMysql.query('SELECT COUNT(*) as tornum FROM `torrents`', function (error, rows, fields) {
stats.torrents = rows[0].tornum;
@ -118,6 +124,9 @@ io.on('connection', function(socket)
if(hash.length != 40)
return;
if(typeof callback != 'function')
return;
socketMysql.query('SELECT * FROM `torrents` WHERE `hash` = ?', hash, function (error, rows, fields) {
if(rows.length == 0) {
callback(undefined);
@ -141,9 +150,14 @@ io.on('connection', function(socket)
socket.on('search', function(text, callback)
{
if(!text || text.length <= 2)
if(typeof callback != 'function')
return;
if(!text || text.length <= 2) {
callback(undefined);
return;
}
let search = {};
console.log(text);