feat(cleaning): fix cleaning checking and removing torrents (also display cleaning status in more details) #52
This commit is contained in:
@ -33,9 +33,29 @@ export default class ConfigPage extends Page {
|
|||||||
archive: __('Archives'),
|
archive: __('Archives'),
|
||||||
disc: __('Discs/ISO')
|
disc: __('Discs/ISO')
|
||||||
}
|
}
|
||||||
|
this.removed = 0
|
||||||
|
this.removedMax = 0
|
||||||
}
|
}
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
this.loadSettings()
|
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() {
|
loadSettings() {
|
||||||
window.torrentSocket.emit('config', window.customLoader((options) => {
|
window.torrentSocket.emit('config', window.customLoader((options) => {
|
||||||
@ -228,6 +248,13 @@ export default class ConfigPage extends Page {
|
|||||||
:
|
:
|
||||||
null
|
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
|
this.settingsSavedMessage
|
||||||
@ -237,12 +264,16 @@ export default class ConfigPage extends Page {
|
|||||||
|
|
||||||
<div className='row center pad0-75'>
|
<div className='row center pad0-75'>
|
||||||
<RaisedButton label={__('Check torrents')} primary={true} onClick={() => {
|
<RaisedButton label={__('Check torrents')} primary={true} onClick={() => {
|
||||||
|
this.toRemoveProbably = null
|
||||||
|
this.toRemove = null
|
||||||
window.torrentSocket.emit('removeTorrents', true, window.customLoader((toRemove) => {
|
window.torrentSocket.emit('removeTorrents', true, window.customLoader((toRemove) => {
|
||||||
this.toRemoveProbably = toRemove
|
this.toRemoveProbably = toRemove
|
||||||
this.forceUpdate()
|
this.forceUpdate()
|
||||||
}));
|
}));
|
||||||
}} />
|
}} />
|
||||||
<RaisedButton label={__('Clean torrents')} secondary={true} onClick={() => {
|
<RaisedButton label={__('Clean torrents')} secondary={true} onClick={() => {
|
||||||
|
this.toRemoveProbably = null
|
||||||
|
this.toRemove = null
|
||||||
window.torrentSocket.emit('removeTorrents', false, window.customLoader((toRemove) => {
|
window.torrentSocket.emit('removeTorrents', false, window.customLoader((toRemove) => {
|
||||||
this.toRemove = toRemove
|
this.toRemove = toRemove
|
||||||
this.forceUpdate()
|
this.forceUpdate()
|
||||||
|
@ -3,6 +3,7 @@ const forBigTable = require('./forBigTable')
|
|||||||
const compareVersions = require('compare-versions');
|
const compareVersions = require('compare-versions');
|
||||||
const getTorrent = require('./gettorrent')
|
const getTorrent = require('./gettorrent')
|
||||||
const _ = require('lodash')
|
const _ = require('lodash')
|
||||||
|
const asyncForEach = require('./asyncForEach')
|
||||||
|
|
||||||
module.exports = async ({
|
module.exports = async ({
|
||||||
sphinx,
|
sphinx,
|
||||||
@ -809,29 +810,44 @@ module.exports = async ({
|
|||||||
})))
|
})))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
let removeProtect = false
|
||||||
recive('removeTorrents', (checkOnly = true, callback) =>
|
recive('removeTorrents', (checkOnly = true, callback) =>
|
||||||
{
|
{
|
||||||
|
if(removeProtect)
|
||||||
|
return
|
||||||
|
removeProtect = true
|
||||||
|
|
||||||
console.log('checktorrents call')
|
console.log('checktorrents call')
|
||||||
|
|
||||||
const toRemove = []
|
const toRemove = []
|
||||||
|
|
||||||
const done = () => {
|
const done = async () => {
|
||||||
console.log('torrents to remove founded', toRemove.length)
|
console.log('torrents to remove founded', toRemove.length)
|
||||||
if(checkOnly)
|
if(checkOnly)
|
||||||
{
|
{
|
||||||
callback(toRemove.length)
|
callback(toRemove.length)
|
||||||
|
removeProtect = false
|
||||||
return
|
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)
|
callback(toRemove.length)
|
||||||
|
removeProtect = false
|
||||||
console.log('removed torrents by filter:', toRemove.length)
|
console.log('removed torrents by filter:', toRemove.length)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let i = 1
|
||||||
forBigTable(sphinx, 'torrents', (torrent) => {
|
forBigTable(sphinx, 'torrents', (torrent) => {
|
||||||
setupTorrentRecord(torrent)
|
setupTorrentRecord(torrent)
|
||||||
if(!checkTorrent(torrent))
|
if(!checkTorrent(torrent))
|
||||||
toRemove.push(torrent)
|
{
|
||||||
|
toRemove.push({hash: torrent.hash})
|
||||||
|
// send info about cleaning takes
|
||||||
|
send('cleanTorrent', i++, 0, 'check');
|
||||||
|
}
|
||||||
}, done)
|
}, done)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -181,6 +181,9 @@
|
|||||||
"* - enabled means ignoring all adult content": "* - enabled means ignoring all adult content",
|
"* - enabled means ignoring all adult content": "* - enabled means ignoring all adult content",
|
||||||
"disable some categories": "disable some categories",
|
"disable some categories": "disable some categories",
|
||||||
"Discs/ISO": "Discs/ISO",
|
"Discs/ISO": "Discs/ISO",
|
||||||
"Torrents to clean": "Torrents to clean"
|
"Torrents to clean": "Torrents to clean",
|
||||||
|
"calculation": "calculation",
|
||||||
|
"removing": "removing",
|
||||||
|
"Torrents cleaned": "Torrents cleaned"
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -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": "Торрентов для очистки",
|
||||||
|
"calculation": "подсчитывается",
|
||||||
|
"removing": "удаляется",
|
||||||
|
"Torrents cleaned": "Torrents cleaned"
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -181,6 +181,9 @@
|
|||||||
"* - enabled means ignoring all adult content": "* - enabled means ignoring all adult content",
|
"* - enabled means ignoring all adult content": "* - enabled means ignoring all adult content",
|
||||||
"disable some categories": "disable some categories",
|
"disable some categories": "disable some categories",
|
||||||
"Discs/ISO": "Discs/ISO",
|
"Discs/ISO": "Discs/ISO",
|
||||||
"Torrents to clean": "Torrents to clean"
|
"Torrents to clean": "Torrents to clean",
|
||||||
|
"calculation": "calculation",
|
||||||
|
"removing": "removing",
|
||||||
|
"Torrents cleaned": "Torrents cleaned"
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user