feat(cleaning): fix cleaning checking and removing torrents (also display cleaning status in more details) #52

This commit is contained in:
Alexey Kasyanchuk 2018-07-24 13:17:40 +03:00
parent a6d9302925
commit e58ffa4531
5 changed files with 62 additions and 6 deletions

View File

@ -33,9 +33,29 @@ export default class ConfigPage extends Page {
archive: __('Archives'),
disc: __('Discs/ISO')
}
this.removed = 0
this.removedMax = 0
}
componentDidMount() {
this.loadSettings()
let time = Date.now() - 1000
this.cleanTorrent = (removed, max, status) => {
if(Date.now() - time < 400)
return
time = Date.now()
this.removed = removed
this.removedMax = max
this.realRemove = (status !== 'check')
this.forceUpdate()
};
window.torrentSocket.on('cleanTorrent', this.cleanTorrent);
}
componentWillUnmount()
{
if(this.cleanTorrent)
window.torrentSocket.off('cleanTorrent', this.cleanTorrent);
}
loadSettings() {
window.torrentSocket.emit('config', window.customLoader((options) => {
@ -228,6 +248,13 @@ export default class ConfigPage extends Page {
:
null
}
{
this.removed > 0 && !this.toRemove && !this.toRemoveProbably
?
<div style={{color: 'purple'}}>{this.realRemove ? __('removing') : __('calculation')}...: {this.removed}{this.removedMax > 0 ? '/' + this.removedMax : ''}</div>
:
null
}
{
this.settingsSavedMessage
@ -237,12 +264,16 @@ export default class ConfigPage extends Page {
<div className='row center pad0-75'>
<RaisedButton label={__('Check torrents')} primary={true} onClick={() => {
this.toRemoveProbably = null
this.toRemove = null
window.torrentSocket.emit('removeTorrents', true, window.customLoader((toRemove) => {
this.toRemoveProbably = toRemove
this.forceUpdate()
}));
}} />
<RaisedButton label={__('Clean torrents')} secondary={true} onClick={() => {
this.toRemoveProbably = null
this.toRemove = null
window.torrentSocket.emit('removeTorrents', false, window.customLoader((toRemove) => {
this.toRemove = toRemove
this.forceUpdate()

View File

@ -3,6 +3,7 @@ const forBigTable = require('./forBigTable')
const compareVersions = require('compare-versions');
const getTorrent = require('./gettorrent')
const _ = require('lodash')
const asyncForEach = require('./asyncForEach')
module.exports = async ({
sphinx,
@ -809,29 +810,44 @@ module.exports = async ({
})))
})
let removeProtect = false
recive('removeTorrents', (checkOnly = true, callback) =>
{
if(removeProtect)
return
removeProtect = true
console.log('checktorrents call')
const toRemove = []
const done = () => {
const done = async () => {
console.log('torrents to remove founded', toRemove.length)
if(checkOnly)
{
callback(toRemove.length)
removeProtect = false
return
}
toRemove.forEach(torrent => removeTorrentFromDB(torrent))
await asyncForEach(toRemove, async (torrent, index) => {
await removeTorrentFromDB(torrent)
send('cleanTorrent', index + 1, toRemove.length, 'clean');
})
callback(toRemove.length)
removeProtect = false
console.log('removed torrents by filter:', toRemove.length)
}
let i = 1
forBigTable(sphinx, 'torrents', (torrent) => {
setupTorrentRecord(torrent)
if(!checkTorrent(torrent))
toRemove.push(torrent)
{
toRemove.push({hash: torrent.hash})
// send info about cleaning takes
send('cleanTorrent', i++, 0, 'check');
}
}, done)
})

View File

@ -181,6 +181,9 @@
"* - enabled means ignoring all adult content": "* - enabled means ignoring all adult content",
"disable some categories": "disable some categories",
"Discs/ISO": "Discs/ISO",
"Torrents to clean": "Torrents to clean"
"Torrents to clean": "Torrents to clean",
"calculation": "calculation",
"removing": "removing",
"Torrents cleaned": "Torrents cleaned"
}
}

View File

@ -181,6 +181,9 @@
"* - enabled means ignoring all adult content": "* - означает игнорирование всего контента для взрослых",
"disable some categories": "отключить некоторые категории",
"Discs/ISO": "Диски/Образы",
"Torrents to clean": "Торрентов для очистки"
"Torrents to clean": "Торрентов для очистки",
"calculation": "подсчитывается",
"removing": "удаляется",
"Torrents cleaned": "Torrents cleaned"
}
}

View File

@ -181,6 +181,9 @@
"* - enabled means ignoring all adult content": "* - enabled means ignoring all adult content",
"disable some categories": "disable some categories",
"Discs/ISO": "Discs/ISO",
"Torrents to clean": "Torrents to clean"
"Torrents to clean": "Torrents to clean",
"calculation": "calculation",
"removing": "removing",
"Torrents cleaned": "Torrents cleaned"
}
}