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 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) {
|
open(pages, params) {
|
||||||
if (params && params.replace) {
|
if (params && params.replace) {
|
||||||
if (params.replace === 'all') {
|
if (params.replace === 'all') {
|
||||||
@ -87,3 +81,5 @@ export default class PagesPie extends Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default singleton(PagesPie)
|
@ -52,14 +52,12 @@ window.router = router;
|
|||||||
|
|
||||||
router('/', () => {
|
router('/', () => {
|
||||||
//singleton
|
//singleton
|
||||||
let pie = new PagesPie;
|
PagesPie.instance().open(IndexPage, {replace: 'all'});
|
||||||
pie.open(IndexPage, {replace: 'all'});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
router('/torrent/:hash', (e) => {
|
router('/torrent/:hash', (e) => {
|
||||||
//singleton
|
//singleton
|
||||||
let pie = new PagesPie;
|
PagesPie.instance().open(TorrentPage, {
|
||||||
pie.open(TorrentPage, {
|
|
||||||
replace: 'all',
|
replace: 'all',
|
||||||
hash: e.params.hash,
|
hash: e.params.hash,
|
||||||
});
|
});
|
||||||
@ -67,26 +65,21 @@ router('/torrent/:hash', (e) => {
|
|||||||
|
|
||||||
router('/DMCA', () => {
|
router('/DMCA', () => {
|
||||||
//singleton
|
//singleton
|
||||||
let pie = new PagesPie;
|
PagesPie.instance().open(DMCAPage, {replace: 'all'});
|
||||||
pie.open(DMCAPage, {replace: 'all'});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
router('/config', () => {
|
router('/config', () => {
|
||||||
//singleton
|
//singleton
|
||||||
let pie = new PagesPie;
|
PagesPie.instance().open(AdminPage, {replace: 'all'});
|
||||||
pie.open(AdminPage, {replace: 'all'});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
router('/top', () => {
|
router('/top', () => {
|
||||||
//singleton
|
//singleton
|
||||||
let pie = new PagesPie;
|
PagesPie.instance().open(TopPage, {replace: 'all'});
|
||||||
pie.open(TopPage, {replace: 'all'});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
router('/changelog', () => {
|
router('/changelog', () => {
|
||||||
//singleton
|
//singleton
|
||||||
let pie = new PagesPie;
|
PagesPie.instance().open(ChangelogPage, {replace: 'all'});
|
||||||
console.log('changelog')
|
|
||||||
pie.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() {
|
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) {
|
if(data) {
|
||||||
this.torrent = data
|
this.torrent = data
|
||||||
this.setTitle(this.torrent.name + ' - Rats On TheBoat');
|
this.setTitle(this.torrent.name + ' - Rats On TheBoat');
|
||||||
|
@ -3,6 +3,9 @@ import formatBytes from './format-bytes'
|
|||||||
import {ListItem} from 'material-ui/List';
|
import {ListItem} from 'material-ui/List';
|
||||||
import Divider from 'material-ui/Divider';
|
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 Spinner24 from './images/spinner_24.gif'
|
||||||
import LinearProgress from 'material-ui/LinearProgress';
|
import LinearProgress from 'material-ui/LinearProgress';
|
||||||
|
|
||||||
@ -212,13 +215,15 @@ export default class Torrent extends Component {
|
|||||||
if(e.button === 1)
|
if(e.button === 1)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
/*
|
||||||
if(e.ctrlKey && e.button === 0) {
|
if(e.ctrlKey && e.button === 0) {
|
||||||
let win = window.open(link, '_blank');
|
let win = window.open(link, '_blank');
|
||||||
//win.focus();
|
//win.focus();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
window.router(link)
|
PagesPie.instance().open(TorrentPage, {replace: 'all', hash: torrent.hash, peer: torrent.peer})
|
||||||
}}
|
}}
|
||||||
primaryText={
|
primaryText={
|
||||||
<a href={'/torrent/' + torrent.hash} ref={(node) => {
|
<a href={'/torrent/' + torrent.hash} ref={(node) => {
|
||||||
|
@ -204,6 +204,13 @@ class p2p {
|
|||||||
return
|
return
|
||||||
return peers.map(peer => ({address: peer.address, port: peer.port}))
|
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
|
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)
|
if(hash.length != 40)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if(typeof callback != 'function')
|
if(typeof callback != 'function')
|
||||||
return;
|
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) {
|
sphinx.query('SELECT * FROM `torrents` WHERE `hash` = ?', hash, function (error, rows, fields) {
|
||||||
if(!rows || rows.length == 0) {
|
if(!rows || rows.length == 0) {
|
||||||
callback(undefined)
|
callback(undefined)
|
||||||
@ -357,7 +374,15 @@ if(dataDirectory && fs.existsSync(dataDirectory + '/peers.p2p'))
|
|||||||
send('downloading', torrent.infoHash)
|
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)
|
const searchTorrentCall = function(text, navigation, callback)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user