This commit is contained in:
Alexey Kasyanchuk
2018-08-18 11:26:05 +03:00
parent 0cd43d674d
commit cebf105691
9 changed files with 102 additions and 102 deletions

View File

@ -25,14 +25,14 @@ let parseDescriptionText = (text) => {
const text = /(.+?:)(.*)/.exec(item) const text = /(.+?:)(.*)/.exec(item)
return ( return (
<span> <span>
{ {
text ? <span><b>{`${text[1]} `}</b>{text[2]}</span> : item text ? <span><b>{`${text[1]} `}</b>{text[2]}</span> : item
} }
<br/> <br/>
</span> </span>
) )
}) })
} }
let buildFilesTree = (filesList) => { let buildFilesTree = (filesList) => {
@ -203,10 +203,10 @@ export default class TorrentPage extends Page {
} }
//this.forceUpdate(); // вызывается через searchingIndicator //this.forceUpdate(); // вызывается через searchingIndicator
// Получаем более новую статистику пира // Получаем более новую статистику пира
if((Date.now() / 1000) - this.torrent.trackersChecked > 10 * 60) { if((Date.now() / 1000) - this.torrent.trackersChecked > 10 * 60) {
window.torrentSocket.emit('checkTrackers', this.torrent.hash); window.torrentSocket.emit('checkTrackers', this.torrent.hash);
} }
} }
}, () => { }, () => {
this.setState({ this.setState({
@ -236,7 +236,7 @@ export default class TorrentPage extends Page {
if(!this.torrent) if(!this.torrent)
return; return;
this.torrent = Object.assign(this.torrent, info); this.torrent = Object.assign(this.torrent, info);
this.forceUpdate(); this.forceUpdate();
} }
window.torrentSocket.on('trackerTorrentUpdate', this.trackerUpdate); window.torrentSocket.on('trackerTorrentUpdate', this.trackerUpdate);
@ -376,7 +376,7 @@ export default class TorrentPage extends Page {
<div style={{flexBasis: '40%'}} className='column center w100p'> <div style={{flexBasis: '40%'}} className='column center w100p'>
<img src={(this.torrent && this.torrent.info && this.torrent.info.poster) ? this.torrent.info.poster : NoImage} className='pad0-75' style={{height: '200px'}} /> <img src={(this.torrent && this.torrent.info && this.torrent.info.poster) ? this.torrent.info.poster : NoImage} className='pad0-75' style={{height: '200px'}} />
<TrackersImages info={this.torrent && this.torrent.info} className='column' /> <TrackersImages info={this.torrent && this.torrent.info} className='column' />
<RaisedButton <RaisedButton
href={`magnet:?xt=urn:btih:${this.torrent.hash}`} href={`magnet:?xt=urn:btih:${this.torrent.hash}`}
target="_self" target="_self"
label="Magnet" label="Magnet"
@ -526,13 +526,13 @@ export default class TorrentPage extends Page {
} }
</div> </div>
</div> </div>
{ {
this.torrent && this.torrent.info && this.torrent.info.description this.torrent && this.torrent.info && this.torrent.info.description
&& &&
<div className='fs0-85' style={{width: '95%', padding: 15, margin: 20, boxShadow: 'rgba(0, 0, 0, 0.12) 0px 1px 6px, rgba(0, 0, 0, 0.12) 0px 1px 4px'}}> <div className='fs0-85' style={{width: '95%', padding: 15, margin: 20, boxShadow: 'rgba(0, 0, 0, 0.12) 0px 1px 6px, rgba(0, 0, 0, 0.12) 0px 1px 4px'}}>
<div>{parseDescriptionText(this.torrent.info.description)}</div> <div>{parseDescriptionText(this.torrent.info.description)}</div>
</div> </div>
} }
</div> </div>
</Tab> </Tab>
<Tab label={__('Files')} value="files" > <Tab label={__('Files')} value="files" >

View File

@ -251,7 +251,7 @@ export default class Torrent extends Component {
{ {
const torrent = this.props.torrent; const torrent = this.props.torrent;
if(!torrent) if(!torrent)
return null // can try draw null torrent (for example on downloading not started) return null // can try draw null torrent (for example on downloading not started)
let torrentRating = -1 let torrentRating = -1
if(torrent.good > 0 || torrent.bad > 0) if(torrent.good > 0 || torrent.bad > 0)
@ -262,8 +262,8 @@ export default class Torrent extends Component {
return ( return (
<div> <div>
<ListItem <ListItem
className='torrentRow' className='torrentRow'
innerDivStyle={{paddingRight: 84}} innerDivStyle={{paddingRight: 84}}
onClick={(e) => { onClick={(e) => {
const link = '/torrent/' + torrent.hash; const link = '/torrent/' + torrent.hash;
@ -358,8 +358,8 @@ export default class Torrent extends Component {
<div style={{marginLeft: 5, color: 'rgb(0, 188, 212)'}}>{this.state.downloadProgress && formatBytes(this.state.downloadProgress.downloadSpeed || 0, 0)}/s</div> <div style={{marginLeft: 5, color: 'rgb(0, 188, 212)'}}>{this.state.downloadProgress && formatBytes(this.state.downloadProgress.downloadSpeed || 0, 0)}/s</div>
} }
</div> </div>
} }
<TrackersImages info={torrent.info} className='row' /> <TrackersImages info={torrent.info} className='row' />
</div> </div>
</a> </a>
} }

View File

@ -6,23 +6,23 @@ import NyaaIcon from './images/strategies/nyaa.jpg'
export default (props) => { export default (props) => {
let className = '' let className = ''
if(props.className) if(props.className)
className += props.className className += props.className
const {info} = props const {info} = props
if(!info) if(!info)
return null return null
return ( return (
<div> <div>
{ {
info.trackers.includes('rutracker') info.trackers.includes('rutracker')
&& &&
<a href={`https://rutracker.org/forum/viewtopic.php?t=${info.rutrackerThreadId}`}><img src={RutrackerIcon} style={{height: 32}} /></a> <a href={`https://rutracker.org/forum/viewtopic.php?t=${info.rutrackerThreadId}`}><img src={RutrackerIcon} style={{height: 32}} /></a>
} }
{ {
info.trackers.includes('nyaa') info.trackers.includes('nyaa')
&& &&
<img src={NyaaIcon} style={{height: 32}} /> <img src={NyaaIcon} style={{height: 32}} />
} }
</div> </div>
) )
} }

View File

@ -1,24 +1,24 @@
const fs = require('fs') const fs = require('fs')
function directoryFilesRecursive (directory, filesList = []) { function directoryFilesRecursive (directory, filesList = []) {
let files; let files;
try { try {
files = fs.readdirSync(directory) files = fs.readdirSync(directory)
} catch(err) { } catch(err) {
if(err.code !== 'ENOTDIR') if(err.code !== 'ENOTDIR')
throw err throw err
else else
return [directory] // if file, return file return [directory] // if file, return file
} }
for (const file of files) { for (const file of files) {
const filePath = `${directory}/${file}` const filePath = `${directory}/${file}`
if (fs.statSync(filePath).isDirectory()) { if (fs.statSync(filePath).isDirectory()) {
directoryFilesRecursive(filePath, filesList) directoryFilesRecursive(filePath, filesList)
} else { } else {
filesList.push(filePath) filesList.push(filePath)
} }
} }
return filesList return filesList
} }
module.exports = directoryFilesRecursive module.exports = directoryFilesRecursive

View File

@ -127,7 +127,7 @@ const expand = (sphinx) => {
key: 'id' key: 'id'
}, options) }, options)
values = Object.assign({}, values) // copy values = Object.assign({}, values) // copy
let names = ''; let names = '';
let data = ''; let data = '';
const parseValues = (values) => { const parseValues = (values) => {

View File

@ -1,11 +1,11 @@
const net = require('net') const net = require('net')
module.exports = (port, host = '127.0.0.1') => new Promise((resolve, reject) => { module.exports = (port, host = '127.0.0.1') => new Promise((resolve, reject) => {
const tester = net.createServer() const tester = net.createServer()
.once('error', err => (err.code === 'EADDRINUSE' ? resolve(false) : reject(err))) .once('error', err => (err.code === 'EADDRINUSE' ? resolve(false) : reject(err)))
.once('listening', () => tester.once('close', () => resolve(true)).close()) .once('listening', () => tester.once('close', () => resolve(true)).close())
.listen({ .listen({
host, host,
port port
}) })
}) })

View File

@ -15,8 +15,8 @@ const portCheck = require('./portCheck')
const findGoodPort = async (port, host) => { const findGoodPort = async (port, host) => {
while (!(await portCheck(port, host))) { while (!(await portCheck(port, host))) {
port++ port++
logT('sphinx', 'port is busy, listen on', port) logT('sphinx', 'port is busy, listen on', port)
} }
return port return port
} }
@ -51,11 +51,11 @@ const writeSphinxConfig = async (path, dbPath) => {
rt_attr_uint = completed rt_attr_uint = completed
rt_attr_timestamp = trackersChecked rt_attr_timestamp = trackersChecked
rt_attr_uint = good rt_attr_uint = good
rt_attr_uint = bad rt_attr_uint = bad
rt_attr_json = info rt_attr_json = info
ngram_len = 1 ngram_len = 1
ngram_chars = U+3000..U+2FA1F ngram_chars = U+3000..U+2FA1F
} }
index files index files

View File

@ -93,8 +93,8 @@ module.exports = function (send, recive, dataDirectory, version, env)
p2p.info.torrents = (await sphinxSingle.query("SELECT COUNT(*) as cnt from torrents"))[0].cnt p2p.info.torrents = (await sphinxSingle.query("SELECT COUNT(*) as cnt from torrents"))[0].cnt
p2p.info.files = (await sphinxSingle.query("SELECT COUNT(*) as cnt from files"))[0].cnt p2p.info.files = (await sphinxSingle.query("SELECT COUNT(*) as cnt from files"))[0].cnt
const sphinxSingleAlternative = await single().waitConnection() const sphinxSingleAlternative = await single().waitConnection()
class RemoteTrackers class RemoteTrackers
{ {
constructor(sphinx) constructor(sphinx)
@ -143,12 +143,12 @@ module.exports = function (send, recive, dataDirectory, version, env)
obj.trackers = [...new Set(obj.trackers)] obj.trackers = [...new Set(obj.trackers)]
info = obj info = obj
} }).then(() => { } }).then(() => {
send('trackerTorrentUpdate', { send('trackerTorrentUpdate', {
hash, hash,
info info
}); });
}) })
}) })
} }
} }
@ -670,21 +670,21 @@ module.exports = function (send, recive, dataDirectory, version, env)
recive('dropTorrents', (pathTorrents) => { recive('dropTorrents', (pathTorrents) => {
logT('drop', 'drop torrents and replicate from original torrent files') logT('drop', 'drop torrents and replicate from original torrent files')
const torrents = _.flatten(pathTorrents.map(path => directoryFilesRecursive(path))) const torrents = _.flatten(pathTorrents.map(path => directoryFilesRecursive(path)))
.filter(path => mime.getType(path) == 'application/x-bittorrent') .filter(path => mime.getType(path) == 'application/x-bittorrent')
.map(path => { .map(path => {
try { try {
return ({ return ({
torrent: parseTorrent(fs.readFileSync(path)), torrent: parseTorrent(fs.readFileSync(path)),
path path
}) })
} catch(err) { } catch(err) {
logT('drop', 'error on parse torrent:', path) logT('drop', 'error on parse torrent:', path)
} }
}) })
.filter(torrent => torrent) .filter(torrent => torrent)
torrents.forEach(({torrent, path}) => { torrents.forEach(({torrent, path}) => {
insertMetadata(torrent, torrent.infoHashBuffer, {address: '127.0.0.1', port: 666}) insertMetadata(torrent, torrent.infoHashBuffer, {address: '127.0.0.1', port: 666})
logT('drop', 'copied torrent to db:', path) logT('drop', 'copied torrent to db:', path)
}) })
logT('drop', 'torrent finish adding to db') logT('drop', 'torrent finish adding to db')
}) })

View File

@ -5,23 +5,23 @@ describe("search", function() {
this.timeout(30000); this.timeout(30000);
it("dht seach", async function() { it("dht seach", async function() {
this.timeout(45000); this.timeout(45000);
const { app } = this const { app } = this
await app.client.waitForExist('#searchInput') await app.client.waitForExist('#searchInput')
await app.client.$('#searchInput').setValue('1413ba1915affdc3de7e1a81d6fdc32ef19395c9') await app.client.$('#searchInput').setValue('1413ba1915affdc3de7e1a81d6fdc32ef19395c9')
await app.client.click('#search') await app.client.click('#search')
await app.client.waitForExist('.torrentRow .torrentName') await app.client.waitForExist('.torrentRow .torrentName')
const value = await app.client.$('.torrentRow .torrentName').getText() const value = await app.client.$('.torrentRow .torrentName').getText()
assert.equal(value, 'Roblox_setup.exe') assert.equal(value, 'Roblox_setup.exe')
}) })
it("sphinx search", async function() { it("sphinx search", async function() {
const { app } = this const { app } = this
await app.client.$('#searchInput').setValue('Roblox_setup') await app.client.$('#searchInput').setValue('Roblox_setup')
await app.client.click('#search') await app.client.click('#search')
await app.client.waitForExist('.torrentRow .torrentName') await app.client.waitForExist('.torrentRow .torrentName')
const results = (await app.client.$$('.torrentRow .torrentName')).length const results = (await app.client.$$('.torrentRow .torrentName')).length
assert(results >= 1, 'default search on Roblox must return Roblox_setup record') assert(results >= 1, 'default search on Roblox must return Roblox_setup record')
}) })
it("sphinx particial search", async function() { it("sphinx particial search", async function() {
@ -31,9 +31,9 @@ describe("search", function() {
await app.client.waitForExist('.torrentRow .torrentName') await app.client.waitForExist('.torrentRow .torrentName')
const results = (await app.client.$$('.torrentRow .torrentName')).length const results = (await app.client.$$('.torrentRow .torrentName')).length
assert(results >= 1, 'particial word search must find string') assert(results >= 1, 'particial word search must find string')
}) })
it("magnet search", async function() { it("magnet search", async function() {
const { app } = this const { app } = this
await app.client.$('#searchInput').setValue('magnet:?xt=urn:btih:1413ba1915affdc3de7e1a81d6fdc32ef19395c9') await app.client.$('#searchInput').setValue('magnet:?xt=urn:btih:1413ba1915affdc3de7e1a81d6fdc32ef19395c9')
await app.client.click('#search') await app.client.click('#search')