исправление при открытии торрента на странице

This commit is contained in:
Alexey Kasyanchuk
2017-01-19 15:54:24 +03:00
parent e6de177361
commit 671c836e24
2 changed files with 19 additions and 2 deletions

View File

@ -451,6 +451,7 @@ client.on('complete', function (metadata, infohash, rinfo) {
filesArray.push(fileQ); filesArray.push(fileQ);
} }
let filesToAdd = filesArray.length;
listenerMysql.query('SELECT count(*) as files_count FROM files WHERE hash = ?', [hash], function(err, rows) { listenerMysql.query('SELECT count(*) as files_count FROM files WHERE hash = ?', [hash], function(err, rows) {
const db_files = rows[0]['files_count']; const db_files = rows[0]['files_count'];
if(db_files !== filesCount) if(db_files !== filesCount)
@ -464,9 +465,12 @@ client.on('complete', function (metadata, infohash, rinfo) {
listenerMysql.query('INSERT INTO files SET ?', file, function(err, result) { listenerMysql.query('INSERT INTO files SET ?', file, function(err, result) {
popDatabaseBalance(); popDatabaseBalance();
if(!result) { if(!result) {
console.log(fileQ); console.log(file);
console.error(err); console.error(err);
} }
if(--filesToAdd === 0) {
io.sockets.emit('filesReady', hash);
}
}); });
}); });
}) })

View File

@ -141,7 +141,7 @@ export default class TorrentPage extends Page {
value: value, value: value,
}); });
}; };
componentDidMount() { getTorrentInfo() {
window.torrentSocket.emit('torrent', this.props.hash, {files: true}, window.customLoader((data) => { window.torrentSocket.emit('torrent', this.props.hash, {files: true}, window.customLoader((data) => {
if(data) { if(data) {
this.torrent = data this.torrent = data
@ -162,6 +162,17 @@ export default class TorrentPage extends Page {
searchingIndicator: false searchingIndicator: false
}); });
})); }));
}
componentDidMount() {
this.getTorrentInfo();
this.filesUpdated = (hash) => {
if(this.props.hash != hash)
return;
this.getTorrentInfo();
}
window.torrentSocket.on('filesReady', this.filesUpdated);
this.trackerUpdate = (info) => { this.trackerUpdate = (info) => {
if(this.props.hash != info.hash) if(this.props.hash != info.hash)
return; return;
@ -175,6 +186,8 @@ export default class TorrentPage extends Page {
window.torrentSocket.on('trackerTorrentUpdate', this.trackerUpdate); window.torrentSocket.on('trackerTorrentUpdate', this.trackerUpdate);
} }
componentWillUnmount() { componentWillUnmount() {
if(this.filesUpdated)
window.torrentSocket.off('filesReady', this.filesUpdated);
if(this.trackerUpdate) if(this.trackerUpdate)
window.torrentSocket.off('trackerTorrentUpdate', this.trackerUpdate); window.torrentSocket.off('trackerTorrentUpdate', this.trackerUpdate);
} }