feat(top): p2p top search
This commit is contained in:
parent
5c777cb629
commit
960731fb80
@ -36,6 +36,18 @@ export default class TopPage extends Page {
|
||||
this.forceUpdate()
|
||||
}))
|
||||
}
|
||||
this.remoteTopTorrents = ({torrents, type}) => {
|
||||
if(!torrents)
|
||||
return
|
||||
this.topTorrents[type] = _.orderBy(_.unionBy(this.topTorrents[type], torrents, 'hash'), ['seeders'], ['desc'])
|
||||
this.forceUpdate();
|
||||
}
|
||||
window.torrentSocket.on('remoteTopTorrents', this.remoteTopTorrents);
|
||||
}
|
||||
componentWillUnmount()
|
||||
{
|
||||
if(this.remoteTopTorrents)
|
||||
window.torrentSocket.off('remoteTopTorrents', this.remoteTopTorrents);
|
||||
}
|
||||
render() {
|
||||
return (
|
||||
|
@ -389,8 +389,7 @@ module.exports = ({
|
||||
updateTorrentTrackers(hash);
|
||||
});
|
||||
|
||||
recive('topTorrents', function(type, callback)
|
||||
{
|
||||
const topTorrentsCall = (type, callback) => {
|
||||
let where = '';
|
||||
let max = 20;
|
||||
if(type && type.length > 0)
|
||||
@ -430,8 +429,27 @@ module.exports = ({
|
||||
topCache[query] = rows;
|
||||
callback(rows);
|
||||
});
|
||||
}
|
||||
|
||||
recive('topTorrents', (type, callback) =>
|
||||
{
|
||||
topTorrentsCall(type, callback)
|
||||
p2p.emit('topTorrents', {type}, (remote, socketObject) => {
|
||||
console.log('remote top results', remote && remote.length)
|
||||
if(remote && remote.length > 0)
|
||||
{
|
||||
const { _socket: socket } = socketObject
|
||||
const peer = { address: socket.remoteAddress, port: socket.remotePort }
|
||||
remote = remote.map(torrent => Object.assign(torrent, {peer}))
|
||||
}
|
||||
send('remoteTopTorrents', {torrents: remote, type})
|
||||
})
|
||||
});
|
||||
|
||||
p2p.on('topTorrents', ({type} = {}, callback) => {
|
||||
topTorrentsCall(type, (data) => callback(data))
|
||||
})
|
||||
|
||||
recive('peers', (callback) =>
|
||||
{
|
||||
if(typeof callback != 'function')
|
||||
|
Loading…
Reference in New Issue
Block a user