Skip to content

Commit

Permalink
feat(cleaning): fix cleaning checking and removing torrents (also dis…
Browse files Browse the repository at this point in the history
…play cleaning status in more details) #52
  • Loading branch information
DEgITx committed Jul 24, 2018
1 parent 9eab5b6 commit 7e0c565
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 6 deletions.
31 changes: 31 additions & 0 deletions src/app/filters-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand Down
22 changes: 19 additions & 3 deletions src/background/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
})

Expand Down
5 changes: 4 additions & 1 deletion translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
5 changes: 4 additions & 1 deletion translations/ru.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
5 changes: 4 additions & 1 deletion translations/ua.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

0 comments on commit 7e0c565

Please sign in to comment.