From 916c421a19ca699d7fd3174fd378ca2a8c6e9e73 Mon Sep 17 00:00:00 2001 From: Alexey Kasyanchuk Date: Wed, 4 Jan 2017 21:19:14 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B2=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6?= =?UTF-8?q?=D0=BD=D0=BE=D0=B9=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B8=20?= =?UTF-8?q?=D0=B7=D0=B0=D0=BF=D1=80=D0=BE=D1=81=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 22 ++++++++++++++++++++-- src/recent-torrents.js | 6 ++++-- src/search.js | 6 ++++-- src/torrent-page.js | 6 ++++-- 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index 3b4aec6..41a0d7d 100644 --- a/index.js +++ b/index.js @@ -87,6 +87,11 @@ io.on('connection', function(socket) return; socketMysql.query('SELECT * FROM `torrents` ORDER BY added DESC LIMIT 0,10', function (error, rows, fields) { + if(!rows) { + callback(undefined) + return; + } + let torrents = []; rows.forEach((row) => { torrents.push(baseRowData(row)); @@ -102,6 +107,11 @@ io.on('connection', function(socket) return; socketMysql.query('SELECT * FROM `statistic`', function (error, rows, fields) { + if(!rows) { + callback(undefined) + return; + } + callback(rows[0]) }); }); @@ -115,8 +125,8 @@ io.on('connection', function(socket) return; socketMysql.query('SELECT * FROM `torrents` WHERE `hash` = ?', hash, function (error, rows, fields) { - if(rows.length == 0) { - callback(undefined); + if(!rows || rows.length == 0) { + callback(undefined) return; } let torrent = rows[0]; @@ -149,6 +159,10 @@ io.on('connection', function(socket) const limit = navigation.limit || 10; let search = {}; socketMysql.query('SELECT * FROM `torrents` WHERE MATCH(`name`) AGAINST(?) LIMIT ?,?', [text, index, limit], function (error, rows, fields) { + if(!rows) { + callback(undefined) + return; + } rows.forEach((row) => { search[row.hash] = baseRowData(row); }); @@ -172,6 +186,10 @@ io.on('connection', function(socket) const limit = navigation.limit || 10; let search = {}; socketMysql.query('SELECT * FROM `files` INNER JOIN torrents ON(torrents.hash = files.hash) WHERE MATCH(`path`) AGAINST(?) LIMIT ?,?', [text, index, limit], function (error, rows, fields) { + if(!rows) { + callback(undefined) + return; + } rows.forEach((row) => { search[row.hash] = baseRowData(row); search[row.hash].path = row.path; diff --git a/src/recent-torrents.js b/src/recent-torrents.js index 3c8f04b..e29f135 100644 --- a/src/recent-torrents.js +++ b/src/recent-torrents.js @@ -149,8 +149,10 @@ export default class RecentTorrents extends Component { } componentDidMount() { window.torrentSocket.emit('recentTorrents', (data) => { - this.torrents = data; - this.forceUpdate(); + if(data) { + this.torrents = data; + this.forceUpdate(); + } }); this.newTorrentFunc = (torrent) => { this.torrents.unshift(torrent); diff --git a/src/search.js b/src/search.js index ab2f320..c448039 100644 --- a/src/search.js +++ b/src/search.js @@ -47,8 +47,10 @@ export default class Search extends Component { } componentDidMount() { this.newStatisticFunc = (statistic) => { - this.stats = statistic; - this.forceUpdate(); + if(statistic) { + this.stats = statistic; + this.forceUpdate(); + } }; window.torrentSocket.emit('statistic', this.newStatisticFunc); window.torrentSocket.on('newStatistic', this.newStatisticFunc); diff --git a/src/torrent-page.js b/src/torrent-page.js index 4cda19b..40a26f2 100644 --- a/src/torrent-page.js +++ b/src/torrent-page.js @@ -138,8 +138,10 @@ export default class TorrentPage extends Component { }; componentDidMount() { window.torrentSocket.emit('torrent', this.props.hash, {files: true}, (data) => { - this.torrent = data - this.forceUpdate(); + if(data) { + this.torrent = data + this.forceUpdate(); + } }); } render() {