From 0549f099f000765514f710a5cd5792ec6099092e Mon Sep 17 00:00:00 2001 From: Alexey Kasyanchuk Date: Mon, 2 Jan 2017 15:15:47 +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=D1=80=D0=BE=D1=83=D1=82=D0=B8=D0=BD?= =?UTF-8?q?=D0=B3=D0=B0,=20=D0=BE=D1=82=D0=BE=D0=B1=D1=80=D0=B0=D0=B6?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BE=D0=B1=D1=89=D0=B5=D0=B9=20?= =?UTF-8?q?=D1=81=D1=82=D0=B0=D1=82=D0=B8=D1=81=D1=82=D0=B8=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 17 +++++++++++++++++ src/search.js | 14 +++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 54d9bb3..7f10549 100644 --- a/index.js +++ b/index.js @@ -69,6 +69,11 @@ app.get('/', function(req, res) app.use(express.static('build')); +app.get('*', function(req, res) +{ + res.sendfile(__dirname + '/build/index.html'); +}); + io.on('connection', function(socket) { function baseRowData(row) @@ -96,6 +101,18 @@ io.on('connection', function(socket) }); }); + socket.on('statistic', function(callback) + { + let stats = {}; + socketMysql.query('SELECT COUNT(*) as tornum FROM `torrents`', function (error, rows, fields) { + stats.torrents = rows[0].tornum; + socketMysql.query('SELECT COUNT(*) as filesnum FROM `files`', function (error, rows, fields) { + stats.files = rows[0].filesnum; + callback(stats) + }); + }); + }); + socket.on('torrent', function(hash, options, callback) { if(hash.length != 40) diff --git a/src/search.js b/src/search.js index efdadf5..23c4de4 100644 --- a/src/search.js +++ b/src/search.js @@ -6,12 +6,17 @@ import RaisedButton from 'material-ui/RaisedButton'; export default class Search extends Component { search() { - console.log(this.searchValue); window.torrentSocket.emit('search', this.searchValue, (torrents) => { this.searchData = torrents; this.forceUpdate(); }); } + componentDidMount() { + window.torrentSocket.emit('statistic', (statistic) => { + this.stats = statistic; + this.forceUpdate(); + }); + } render() { return (
@@ -32,6 +37,13 @@ export default class Search extends Component { this.search() }} />
+ { + this.stats + ? +
we have {this.stats.torrents} torrents and around {this.stats.files} files here
+ : + null + } );