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)
return (
<span>
{
text ? <span><b>{`${text[1]} `}</b>{text[2]}</span> : item
}
<br/>
</span>
<span>
{
text ? <span><b>{`${text[1]} `}</b>{text[2]}</span> : item
}
<br/>
</span>
)
})
})
}
let buildFilesTree = (filesList) => {
@ -203,10 +203,10 @@ export default class TorrentPage extends Page {
}
//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);
}
}
}
}, () => {
this.setState({
@ -236,7 +236,7 @@ export default class TorrentPage extends Page {
if(!this.torrent)
return;
this.torrent = Object.assign(this.torrent, info);
this.torrent = Object.assign(this.torrent, info);
this.forceUpdate();
}
window.torrentSocket.on('trackerTorrentUpdate', this.trackerUpdate);
@ -376,7 +376,7 @@ export default class TorrentPage extends Page {
<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'}} />
<TrackersImages info={this.torrent && this.torrent.info} className='column' />
<RaisedButton
<RaisedButton
href={`magnet:?xt=urn:btih:${this.torrent.hash}`}
target="_self"
label="Magnet"
@ -526,13 +526,13 @@ export default class TorrentPage extends Page {
}
</div>
</div>
{
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>{parseDescriptionText(this.torrent.info.description)}</div>
</div>
}
{
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>{parseDescriptionText(this.torrent.info.description)}</div>
</div>
}
</div>
</Tab>
<Tab label={__('Files')} value="files" >

View File

@ -251,7 +251,7 @@ export default class Torrent extends Component {
{
const torrent = this.props.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
if(torrent.good > 0 || torrent.bad > 0)
@ -262,8 +262,8 @@ export default class Torrent extends Component {
return (
<div>
<ListItem
className='torrentRow'
<ListItem
className='torrentRow'
innerDivStyle={{paddingRight: 84}}
onClick={(e) => {
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>
}
<TrackersImages info={torrent.info} className='row' />
}
<TrackersImages info={torrent.info} className='row' />
</div>
</a>
}

View File

@ -6,23 +6,23 @@ import NyaaIcon from './images/strategies/nyaa.jpg'
export default (props) => {
let className = ''
if(props.className)
className += props.className
const {info} = props
if(!info)
return null
className += props.className
const {info} = props
if(!info)
return null
return (
<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>
}
{
info.trackers.includes('nyaa')
}
{
info.trackers.includes('nyaa')
&&
<img src={NyaaIcon} style={{height: 32}} />
}
</div>
}
</div>
)
}

View File

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

View File

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

View File

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

View File

@ -143,7 +143,7 @@ module.exports = function (send, recive, dataDirectory, version, env)
obj.trackers = [...new Set(obj.trackers)]
info = obj
} }).then(() => {
} }).then(() => {
send('trackerTorrentUpdate', {
hash,
info
@ -670,21 +670,21 @@ module.exports = function (send, recive, dataDirectory, version, env)
recive('dropTorrents', (pathTorrents) => {
logT('drop', 'drop torrents and replicate from original torrent files')
const torrents = _.flatten(pathTorrents.map(path => directoryFilesRecursive(path)))
.filter(path => mime.getType(path) == 'application/x-bittorrent')
.map(path => {
try {
return ({
torrent: parseTorrent(fs.readFileSync(path)),
path
})
} catch(err) {
logT('drop', 'error on parse torrent:', path)
}
})
.filter(torrent => torrent)
.filter(path => mime.getType(path) == 'application/x-bittorrent')
.map(path => {
try {
return ({
torrent: parseTorrent(fs.readFileSync(path)),
path
})
} catch(err) {
logT('drop', 'error on parse torrent:', path)
}
})
.filter(torrent => torrent)
torrents.forEach(({torrent, path}) => {
insertMetadata(torrent, torrent.infoHashBuffer, {address: '127.0.0.1', port: 666})
logT('drop', 'copied torrent to db:', path)
insertMetadata(torrent, torrent.infoHashBuffer, {address: '127.0.0.1', port: 666})
logT('drop', 'copied torrent to db:', path)
})
logT('drop', 'torrent finish adding to db')
})

View File

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