fix(search): show torrent page from remote peer
This commit is contained in:
parent
857bc66c7f
commit
1c626fa2bf
@ -1,15 +1,9 @@
|
||||
import React, { Component } from 'react';
|
||||
import singleton from './singleton'
|
||||
|
||||
class PagesPie extends Component {
|
||||
pie = [];
|
||||
|
||||
export default class PagesPie extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
// синглтон
|
||||
if ( PagesPie.instance ) {
|
||||
return PagesPie.instance;
|
||||
}
|
||||
PagesPie.instance = this;
|
||||
this.pie = [];
|
||||
}
|
||||
open(pages, params) {
|
||||
if (params && params.replace) {
|
||||
if (params.replace === 'all') {
|
||||
@ -86,4 +80,6 @@ export default class PagesPie extends Component {
|
||||
return null
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default singleton(PagesPie)
|
@ -52,14 +52,12 @@ window.router = router;
|
||||
|
||||
router('/', () => {
|
||||
//singleton
|
||||
let pie = new PagesPie;
|
||||
pie.open(IndexPage, {replace: 'all'});
|
||||
PagesPie.instance().open(IndexPage, {replace: 'all'});
|
||||
});
|
||||
|
||||
router('/torrent/:hash', (e) => {
|
||||
//singleton
|
||||
let pie = new PagesPie;
|
||||
pie.open(TorrentPage, {
|
||||
PagesPie.instance().open(TorrentPage, {
|
||||
replace: 'all',
|
||||
hash: e.params.hash,
|
||||
});
|
||||
@ -67,26 +65,21 @@ router('/torrent/:hash', (e) => {
|
||||
|
||||
router('/DMCA', () => {
|
||||
//singleton
|
||||
let pie = new PagesPie;
|
||||
pie.open(DMCAPage, {replace: 'all'});
|
||||
PagesPie.instance().open(DMCAPage, {replace: 'all'});
|
||||
});
|
||||
|
||||
|
||||
router('/config', () => {
|
||||
//singleton
|
||||
let pie = new PagesPie;
|
||||
pie.open(AdminPage, {replace: 'all'});
|
||||
PagesPie.instance().open(AdminPage, {replace: 'all'});
|
||||
});
|
||||
|
||||
router('/top', () => {
|
||||
//singleton
|
||||
let pie = new PagesPie;
|
||||
pie.open(TopPage, {replace: 'all'});
|
||||
PagesPie.instance().open(TopPage, {replace: 'all'});
|
||||
});
|
||||
|
||||
router('/changelog', () => {
|
||||
//singleton
|
||||
let pie = new PagesPie;
|
||||
console.log('changelog')
|
||||
pie.open(ChangelogPage, {replace: 'all'});
|
||||
PagesPie.instance().open(ChangelogPage, {replace: 'all'});
|
||||
});
|
29
src/app/singleton.js
Normal file
29
src/app/singleton.js
Normal file
@ -0,0 +1,29 @@
|
||||
export default (Superclass) => {
|
||||
let instance;
|
||||
|
||||
return class Singleton extends Superclass {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
if (instance) {
|
||||
instance.props = props
|
||||
return instance;
|
||||
}
|
||||
instance = this;
|
||||
}
|
||||
static instance() {
|
||||
if (instance) {
|
||||
return instance;
|
||||
} else {
|
||||
return new Singleton();
|
||||
}
|
||||
}
|
||||
static do(key, ...params) {
|
||||
if ( typeof this.instance()[key] === 'function') {
|
||||
return this.instance()[key](...params);
|
||||
} else {
|
||||
return this.instance()[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -180,7 +180,7 @@ export default class TorrentPage extends Page {
|
||||
});
|
||||
};
|
||||
getTorrentInfo() {
|
||||
window.torrentSocket.emit('torrent', this.props.hash, {files: true}, window.customLoader((data) => {
|
||||
window.torrentSocket.emit('torrent', this.props.hash, {files: true, peer: this.props.peer}, window.customLoader((data) => {
|
||||
if(data) {
|
||||
this.torrent = data
|
||||
this.setTitle(this.torrent.name + ' - Rats On TheBoat');
|
||||
|
@ -3,6 +3,9 @@ import formatBytes from './format-bytes'
|
||||
import {ListItem} from 'material-ui/List';
|
||||
import Divider from 'material-ui/Divider';
|
||||
|
||||
import PagesPie from './pages-pie.js';
|
||||
import TorrentPage from './torrent-page'
|
||||
|
||||
import Spinner24 from './images/spinner_24.gif'
|
||||
import LinearProgress from 'material-ui/LinearProgress';
|
||||
|
||||
@ -212,13 +215,15 @@ export default class Torrent extends Component {
|
||||
if(e.button === 1)
|
||||
return false;
|
||||
|
||||
/*
|
||||
if(e.ctrlKey && e.button === 0) {
|
||||
let win = window.open(link, '_blank');
|
||||
//win.focus();
|
||||
return true;
|
||||
}
|
||||
*/
|
||||
|
||||
window.router(link)
|
||||
PagesPie.instance().open(TorrentPage, {replace: 'all', hash: torrent.hash, peer: torrent.peer})
|
||||
}}
|
||||
primaryText={
|
||||
<a href={'/torrent/' + torrent.hash} ref={(node) => {
|
||||
|
@ -204,6 +204,13 @@ class p2p {
|
||||
return
|
||||
return peers.map(peer => ({address: peer.address, port: peer.port}))
|
||||
}
|
||||
|
||||
find(peer)
|
||||
{
|
||||
return this.peersList().find((localPeer) => {
|
||||
return localPeer.address === peer.address
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = p2p
|
@ -321,14 +321,31 @@ if(dataDirectory && fs.existsSync(dataDirectory + '/peers.p2p'))
|
||||
});
|
||||
});
|
||||
|
||||
recive('torrent', function(hash, options, callback)
|
||||
{
|
||||
const onTorrent = (hash, options, callback) => {
|
||||
if(hash.length != 40)
|
||||
return;
|
||||
|
||||
if(typeof callback != 'function')
|
||||
return;
|
||||
|
||||
// remote request
|
||||
if(options.peer)
|
||||
{
|
||||
console.log('remote torrent request to peer')
|
||||
const peer = p2p.find(options.peer)
|
||||
if(!peer)
|
||||
{
|
||||
callback(undefined)
|
||||
return;
|
||||
}
|
||||
delete options.peer;
|
||||
peer.emit('torrent', {hash, options}, (data) => {
|
||||
console.log('remote torrent result')
|
||||
callback(data)
|
||||
})
|
||||
return;
|
||||
}
|
||||
|
||||
sphinx.query('SELECT * FROM `torrents` WHERE `hash` = ?', hash, function (error, rows, fields) {
|
||||
if(!rows || rows.length == 0) {
|
||||
callback(undefined)
|
||||
@ -357,7 +374,15 @@ if(dataDirectory && fs.existsSync(dataDirectory + '/peers.p2p'))
|
||||
send('downloading', torrent.infoHash)
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
recive('torrent', onTorrent);
|
||||
p2p.on('torrent', ({hash, options} = {}, callback) => {
|
||||
if(!hash)
|
||||
return;
|
||||
|
||||
onTorrent(hash, options, (data) => callback(data))
|
||||
})
|
||||
|
||||
const searchTorrentCall = function(text, navigation, callback)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user