This commit is contained in:
Alexey Kasyanchuk 2018-11-11 23:59:38 +03:00
parent 6afe85798a
commit aa75d75448
13 changed files with 129 additions and 129 deletions

View File

@ -15,31 +15,31 @@ class PagesPie extends Component {
delete params.replace; delete params.replace;
} }
if (Array.isArray(pages)) { if (Array.isArray(pages)) {
for (let i in pages) { for (let i in pages) {
this.pie.push({ this.pie.push({
Page: pages[i], Page: pages[i],
params: params params: params
}); });
} }
} else { } else {
this.pie.push({ this.pie.push({
Page: pages, Page: pages,
params: params params: params
}); });
} }
if(this._mounted) if(this._mounted)
this.forceUpdate() this.forceUpdate()
} }
componentWillMount() componentWillMount()
{ {
this._mounted = true this._mounted = true
} }
componentWillUnmount() componentWillUnmount()
{ {
this._mounted = false this._mounted = false
} }
close(count) { close(count) {
if (count && typeof count === 'number') { if (count && typeof count === 'number') {
@ -59,7 +59,7 @@ class PagesPie extends Component {
} }
// ОТРИСОВКА // ОТРИСОВКА
render() { render() {
if (this.pie.length > 0) { if (this.pie.length > 0) {
return ( return (
<div <div
className={'pie full-size ' + (this.props.className || '')} className={'pie full-size ' + (this.props.className || '')}

View File

@ -104,19 +104,19 @@ const treeToTorrentFiles = (tree, torrent, toggles) => {
leftIcon={!tree[file].__fileBT ? <FileFolder /> : contentIcon(fileTypeDetect({path: file}))} leftIcon={!tree[file].__fileBT ? <FileFolder /> : contentIcon(fileTypeDetect({path: file}))}
rightToggle={ rightToggle={
newToggles.length > 0 newToggles.length > 0
? ?
<Toggle <Toggle
toggled={newToggles.every( ({selected}) => selected )} toggled={newToggles.every( ({selected}) => selected )}
onToggle={(e, checked) => { onToggle={(e, checked) => {
e.preventDefault() e.preventDefault()
e.stopPropagation() e.stopPropagation()
let toggleValues = {} let toggleValues = {}
newToggles.forEach(({downloadIndex}) => toggleValues[downloadIndex] = checked) newToggles.forEach(({downloadIndex}) => toggleValues[downloadIndex] = checked)
window.torrentSocket.emit('downloadSelectFiles', torrent, toggleValues) window.torrentSocket.emit('downloadSelectFiles', torrent, toggleValues)
}} }}
/> />
: :
null null
} }
/>); />);

View File

@ -302,13 +302,13 @@ export default class Torrent extends Component {
node.onclick = () => { return false } node.onclick = () => { return false }
}}> }}>
<div className='column' style={{height: 'auto', whiteSpace: 'normal', paddingTop: '0.30em'}}> <div className='column' style={{height: 'auto', whiteSpace: 'normal', paddingTop: '0.30em'}}>
{ {
torrent.info && torrent.info.name torrent.info && torrent.info.name
&& &&
<div className='row w100p inline fs0-85' style={{color: 'grey', padding: '4px 0px 5px'}}> <div className='row w100p inline fs0-85' style={{color: 'grey', padding: '4px 0px 5px'}}>
{torrent.info.name} {torrent.info.name}
</div> </div>
} }
<div className='row w100p inline'> <div className='row w100p inline'>
<div style={{color: torrent.contentCategory != 'xxx' ? (torrent.peer ? '#5252d1' : 'black') : (torrent.peer ? '#9083e2' : 'grey')}}> <div style={{color: torrent.contentCategory != 'xxx' ? (torrent.peer ? '#5252d1' : 'black') : (torrent.peer ? '#9083e2' : 'grey')}}>
{ {
@ -320,17 +320,17 @@ export default class Torrent extends Component {
torrent.path && torrent.path.length > 0 torrent.path && torrent.path.length > 0
? ?
torrent.path.map((path, index) => { torrent.path.map((path, index) => {
const boldRe = /\<b\>(.+?)\<\/b\>/g; const boldRe = /\<b\>(.+?)\<\/b\>/g;
let boldText; let boldText;
let newPath = []; let newPath = [];
let idx = 0; let idx = 0;
while ((boldText = boldRe.exec(path)) !== null) { while ((boldText = boldRe.exec(path)) !== null) {
newPath.push(<span>{path.substring(idx, boldText.index)}</span>); newPath.push(<span>{path.substring(idx, boldText.index)}</span>);
newPath.push(<b>{boldText[1]}</b>); newPath.push(<b>{boldText[1]}</b>);
idx = boldRe.lastIndex; idx = boldRe.lastIndex;
} }
newPath.push(<span>{path.substring(idx, path.length)}</span>); newPath.push(<span>{path.substring(idx, path.length)}</span>);
return <div key={index} className='break-word fs0-75' style={{paddingTop: '0.3em', marginLeft: '0.6em'}}>{newPath}</div> return <div key={index} className='break-word fs0-75' style={{paddingTop: '0.3em', marginLeft: '0.6em'}}>{newPath}</div>
}) })
: :
null null

View File

@ -30,7 +30,7 @@ export default (props) => {
{ {
info.trackers.includes('rutor') info.trackers.includes('rutor')
&& &&
<a href={`http://www.rutor.is/torrent/${info.rutorThreadId}`}><img src={RutorIcon} style={{height: 32}} /></a> <a href={`http://www.rutor.is/torrent/${info.rutorThreadId}`}><img src={RutorIcon} style={{height: 32}} /></a>
} }
</div> </div>
) )

View File

@ -243,7 +243,7 @@ module.exports = async ({
sphinxSingle.query(`SELECT * FROM files WHERE hash IN(${inSql})`, (error, files) => { sphinxSingle.query(`SELECT * FROM files WHERE hash IN(${inSql})`, (error, files) => {
for(const file of files) for(const file of files)
hashes[file.hash].filesList = parseTorrentFiles(file); hashes[file.hash].filesList = parseTorrentFiles(file);
callback(Object.values(hashes)) callback(Object.values(hashes))
}) })
}) })

View File

@ -74,24 +74,24 @@ module.exports = async (callback, mainWindow, sphinxApp) => {
} }
#one { #one {
padding: 20px; padding: 20px;
} }
#long { #long {
font-size: 0.8em; font-size: 0.8em;
padding: 10px; padding: 10px;
} }
#canBreak { #canBreak {
font-size: 0.8em; font-size: 0.8em;
padding: 10px; padding: 10px;
} }
</style> </style>
<script> <script>
const {ipcRenderer} = require('electron') const {ipcRenderer} = require('electron')
ipcRenderer.on('reindex', (e, data) =>{ ipcRenderer.on('reindex', (e, data) =>{
document.getElementById('one').innerHTML = \`Updating \${data.torrent ? 'torrent': 'file'} \${data.index} of \${data.all} [\${data.field} index]\` document.getElementById('one').innerHTML = \`Updating \${data.torrent ? 'torrent': 'file'} \${data.index} of \${data.all} [\${data.field} index]\`
if(data.longTime) if(data.longTime)
document.getElementById('long').innerHTML = 'This patch is very long, may be some hours. So you can take some cup of tea, while we perform db patch.' document.getElementById('long').innerHTML = 'This patch is very long, may be some hours. So you can take some cup of tea, while we perform db patch.'
if(data.canBreak) if(data.canBreak)
document.getElementById('canBreak').innerHTML = 'You can break this patch, and continue when you will have time to patch, it will be resumed.' document.getElementById('canBreak').innerHTML = 'You can break this patch, and continue when you will have time to patch, it will be resumed.'
}) })
ipcRenderer.on('optimize', (e, data) =>{ ipcRenderer.on('optimize', (e, data) =>{
document.getElementById('one').innerHTML = \`Optimization for \${data.field}...\` document.getElementById('one').innerHTML = \`Optimization for \${data.field}...\`
@ -108,9 +108,9 @@ module.exports = async (callback, mainWindow, sphinxApp) => {
c4.416,0.15,17.979,1.621,17.683-4.273c-0.292-5.897-11.491-3.241-13.854-6.487c-2.359-3.234-10.023-15.504-7.366-21.104 c4.416,0.15,17.979,1.621,17.683-4.273c-0.292-5.897-11.491-3.241-13.854-6.487c-2.359-3.234-10.023-15.504-7.366-21.104
c2.65-5.59,12.674-21.229,24.463-22.988c11.789-1.777,42.451,7.361,47.459,0c5.012-7.372-6.783-11.512-15.918-28.611 c2.65-5.59,12.674-21.229,24.463-22.988c11.789-1.777,42.451,7.361,47.459,0c5.012-7.372-6.783-11.512-15.918-28.611
C243.779,80.572,238.768,71.728,220.195,71.427z"/> C243.779,80.572,238.768,71.728,220.195,71.427z"/>
<div id="one"></div> <div id="one"></div>
<div id="long"></div> <div id="long"></div>
<div id="canBreak"></div> <div id="canBreak"></div>
</svg> </svg>
</body> </body>
</html> </html>
@ -349,7 +349,7 @@ module.exports = async (callback, mainWindow, sphinxApp) => {
} }
newId++; newId++;
logT('patcher', 'founded newId', newId); logT('patcher', 'founded newId', newId);
logT('patcher', 'perform optimization'); logT('patcher', 'perform optimization');
sphinx.query(`OPTIMIZE INDEX files`) sphinx.query(`OPTIMIZE INDEX files`)
await sphinxApp.waitOptimized('files') await sphinxApp.waitOptimized('files')
@ -363,7 +363,7 @@ module.exports = async (callback, mainWindow, sphinxApp) => {
if(Field == 'size' && Type == 'string') if(Field == 'size' && Type == 'string')
isSizeAlreadyPatched = true; isSizeAlreadyPatched = true;
}); });
if(!isSizeNewExists) if(!isSizeNewExists)
await sphinx.query("alter table files add column `size_new` string"); await sphinx.query("alter table files add column `size_new` string");
else else

View File

@ -1,15 +1,15 @@
const fs = require('fs') const fs = require('fs')
module.exports = function deleteFolderRecursive(path) { module.exports = function deleteFolderRecursive(path) {
if (fs.existsSync(path)) { if (fs.existsSync(path)) {
fs.readdirSync(path).forEach(function(file, index){ fs.readdirSync(path).forEach(function(file, index){
var curPath = path + "/" + file; var curPath = path + "/" + file;
if (fs.lstatSync(curPath).isDirectory()) { // recurse if (fs.lstatSync(curPath).isDirectory()) { // recurse
deleteFolderRecursive(curPath); deleteFolderRecursive(curPath);
} else { // delete file } else { // delete file
fs.unlinkSync(curPath); fs.unlinkSync(curPath);
} }
}); });
fs.rmdirSync(path); fs.rmdirSync(path);
} }
}; };

View File

@ -105,10 +105,10 @@ module.exports = class Feed {
const relativeTime = (maxTime - time) / maxTime const relativeTime = (maxTime - time) / maxTime
return ( return (
relativeTime * relativeTime relativeTime * relativeTime
+ good * 1.5 * relativeTime + good * 1.5 * relativeTime
+ comments * 4 * relativeTime + comments * 4 * relativeTime
- bad * 0.6 * relativeTime - bad * 0.6 * relativeTime
+ rating(good, bad) + rating(good, bad)
) )
} }
} }

View File

@ -460,7 +460,7 @@ class p2p {
let fileStream let fileStream
if(!fs.existsSync(tmpPath) || !fs.lstatSync(tmpPath).isDirectory()) if(!fs.existsSync(tmpPath) || !fs.lstatSync(tmpPath).isDirectory())
fileStream = fs.createWriteStream(tmpPath) fileStream = fs.createWriteStream(tmpPath)
let peer = null let peer = null
let firstTransfer = false let firstTransfer = false
let deleteCallback = (remotePeer || this).emit('file', {path}, async (chunk, nil, addr) => { let deleteCallback = (remotePeer || this).emit('file', {path}, async (chunk, nil, addr) => {
@ -514,11 +514,11 @@ class p2p {
if(fileStream) if(fileStream)
fileStream.end(null, null, () => { fileStream.end(null, null, () => {
fs.unlinkSync(tmpPath) fs.unlinkSync(tmpPath)
transferFiles() transferFiles()
}) })
else else
transferFiles() transferFiles()
return return
} }
@ -546,7 +546,7 @@ class p2p {
firstTransfer = true firstTransfer = true
logT('transfer', 'got peer for tranfer, start transfering file', path, 'from peer', addr.peerId) logT('transfer', 'got peer for tranfer, start transfering file', path, 'from peer', addr.peerId)
} }
const buffer = Buffer.from(data.data) const buffer = Buffer.from(data.data)
fileStream.write(buffer) fileStream.write(buffer)
}, true) // dont clear callback }, true) // dont clear callback

View File

@ -4,7 +4,7 @@ module.exports = (filesData) => {
let path = filesData.path.split('\n'); let path = filesData.path.split('\n');
let size = filesData.size.split('\n'); let size = filesData.size.split('\n');
return path.map((pathString, index) => Object.assign({}, filesData, { return path.map((pathString, index) => Object.assign({}, filesData, {
path: pathString, path: pathString,
size: parseInt(size[index]) size: parseInt(size[index])

View File

@ -551,7 +551,7 @@ module.exports = function (send, recive, dataDirectory, version, env)
path, path,
pathIndex: path, pathIndex: path,
size size
}, function(err, result) { }, function(err, result) {
if(!result) { if(!result) {
console.error(err); console.error(err);
return return
@ -913,7 +913,7 @@ module.exports = function (send, recive, dataDirectory, version, env)
// save feed // save feed
await feed.save() await feed.save()
// close trackers if needed // close trackers if needed
logT('close', 'closing trackers') logT('close', 'closing trackers')
await remoteTrackers.close() await remoteTrackers.close()

View File

@ -59,14 +59,14 @@ module.exports = class Rutor
if(!this.dataDirectory) if(!this.dataDirectory)
return return
if(!this.rutorMap && fs.existsSync(this.dataDirectory + '/rutor/rutor.x.json')) if(!this.rutorMap && fs.existsSync(this.dataDirectory + '/rutor/rutor.x.json'))
{ {
let data = JSON.parse(fs.readFileSync(this.dataDirectory + '/rutor/rutor.x.json')) let data = JSON.parse(fs.readFileSync(this.dataDirectory + '/rutor/rutor.x.json'))
this.rutorMap = data.hashes this.rutorMap = data.hashes
logT('rutor', 'add records to', Object.keys(this.rutorMap).length) logT('rutor', 'add records to', Object.keys(this.rutorMap).length)
} }
else if(!this.rutorMap) else if(!this.rutorMap)
this.rutorMap = {} this.rutorMap = {}
if(page > 10) if(page > 10)
{ {
@ -84,29 +84,29 @@ module.exports = class Rutor
return return
html = await html.textConverted() html = await html.textConverted()
const $ = cheerio.load(html) const $ = cheerio.load(html)
const rutorMap = this.rutorMap const rutorMap = this.rutorMap
$('#index tr').each(function(i, elem) { $('#index tr').each(function(i, elem) {
const row = $(this) const row = $(this)
const nameField = row.find('td').next() const nameField = row.find('td').next()
if(!nameField) if(!nameField)
return return
let id = nameField.find('a').attr('href') let id = nameField.find('a').attr('href')
if(!id) if(!id)
return return
id = id.match(/download\/([0-9]+)/)[1] id = id.match(/download\/([0-9]+)/)[1]
id = parseInt(id) id = parseInt(id)
const hash = magnetParse(nameField.find('a').next().attr('href')) const hash = magnetParse(nameField.find('a').next().attr('href'))
rutorMap[hash] = id rutorMap[hash] = id
}); });
await mkdirp(`${this.dataDirectory}/rutor`) await mkdirp(`${this.dataDirectory}/rutor`)
fs.writeFileSync(`${this.dataDirectory}/rutor/rutor.x.json`, JSON.stringify({ fs.writeFileSync(`${this.dataDirectory}/rutor/rutor.x.json`, JSON.stringify({
date: Date.now(), date: Date.now(),
hashes: this.rutorMap hashes: this.rutorMap
}, null, 4), 'utf8'); }, null, 4), 'utf8');
logT('rutor', 'parse new links page', page) logT('rutor', 'parse new links page', page)
setTimeout(() => this.recheck(page + 1), 30) setTimeout(() => this.recheck(page + 1), 30)
} }
@ -130,14 +130,14 @@ module.exports = class Rutor
let contentCategory let contentCategory
$('#details tr').each(function(i, elem) { $('#details tr').each(function(i, elem) {
const row = $(this) const row = $(this)
const field = row.find('td.header').text() const field = row.find('td.header').text()
if(field == 'Категория') if(field == 'Категория')
{ {
contentCategory = row.find('td').next().text().trim() contentCategory = row.find('td').next().text().trim()
} }
}); });
return { return {
name: topicTitle, name: topicTitle,
@ -146,7 +146,7 @@ module.exports = class Rutor
rutorThreadId: parseInt(id), rutorThreadId: parseInt(id),
contentCategory contentCategory
} }
} }
} }

View File

@ -36,7 +36,7 @@ describe("sphinx", () => {
throw new Error(err) throw new Error(err)
if(result.length !== 1) if(result.length !== 1)
throw new Error('not one result') throw new Error('not one result')
if(result[0].size != 50) if(result[0].size != 50)
throw new Error('not 50 in field') throw new Error('not 50 in field')