исправление при открытии торрента на странице
This commit is contained in:
6
index.js
6
index.js
@ -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);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user