feat(filter): naming filtering #17

This commit is contained in:
Alexey Kasyanchuk 2018-04-01 23:35:55 +03:00
parent 5348d1f88f
commit 99d9004906
3 changed files with 47 additions and 14 deletions

View File

@ -77,20 +77,26 @@ export default class ConfigPage extends Page {
</div> </div>
</div> </div>
<div className='column w100p'>
<div className='row inline w100p'>
<div style={{flex: 1}}>Torrent name regular extension filtering</div>
<TextField
hintText="regex"
className='pad0-75'
style={{width: 400}}
value={this.options.filters && this.options.filters.namingRegExp}
onChange={(e, value) => {
if(!this.options.filters)
return
<div className='row center pad0-75'> this.options.filters.namingRegExp = value
<RaisedButton label="Check torrents" primary={true} onClick={() => {
window.torrentSocket.emit('removeTorrents', true, window.customLoader((toRemove) => {
this.toRemoveProbably = toRemove
this.forceUpdate() this.forceUpdate()
})); }}
}} /> />
<RaisedButton label="Clean torrents" secondary={true} onClick={() => { </div>
window.torrentSocket.emit('removeTorrents', false, window.customLoader((toRemove) => { <div className='fs0-75' style={{color: 'grey'}}>
this.toRemove = toRemove * - clean string means disabled
this.forceUpdate() </div>
}));
}} />
</div> </div>
{ {
@ -114,6 +120,21 @@ export default class ConfigPage extends Page {
<div style={{color: 'green'}}>Settings saved</div> <div style={{color: 'green'}}>Settings saved</div>
} }
<div className='row center pad0-75'>
<RaisedButton label="Check torrents" primary={true} onClick={() => {
window.torrentSocket.emit('removeTorrents', true, window.customLoader((toRemove) => {
this.toRemoveProbably = toRemove
this.forceUpdate()
}));
}} />
<RaisedButton label="Clean torrents" secondary={true} onClick={() => {
window.torrentSocket.emit('removeTorrents', false, window.customLoader((toRemove) => {
this.toRemove = toRemove
this.forceUpdate()
}));
}} />
</div>
<div className='row center pad0-75'> <div className='row center pad0-75'>
<RaisedButton label="Save Settings" primary={true} onClick={() => { <RaisedButton label="Save Settings" primary={true} onClick={() => {
this.saveSettings() this.saveSettings()

View File

@ -38,6 +38,7 @@ let config = {
filters: { filters: {
maxFiles: 0, maxFiles: 0,
namingRegExp: ''
}, },
cleanup: true, cleanup: true,

View File

@ -454,6 +454,17 @@ const checkTorrent = (torrent) => {
return false return false
} }
const nameRX = config.filters.namingRegExp && config.filters.namingRegExp.trim()
if(nameRX && nameRX.length > 0)
{
const rx = new RegExp(nameRX)
if(!rx.test(torrent.name))
{
console.log('ignore', torrent.name, 'by naming rx')
return false
}
}
return true return true
} }