From 8792da82d53e16d49ebcbe7301151529af9cf1be Mon Sep 17 00:00:00 2001 From: Alexey Kasyanchuk Date: Wed, 18 Jul 2018 10:23:32 +0300 Subject: [PATCH] feat(filters): content type filters #49 --- src/app/filters-page.js | 56 +++++++++++++++++++++++++++++++++++++--- src/background/spider.js | 6 +++++ translations/en.json | 4 ++- translations/ru.json | 4 ++- translations/ua.json | 4 ++- 5 files changed, 68 insertions(+), 6 deletions(-) diff --git a/src/app/filters-page.js b/src/app/filters-page.js index fc59768..653e2b6 100644 --- a/src/app/filters-page.js +++ b/src/app/filters-page.js @@ -8,14 +8,31 @@ import Slider from 'material-ui/Slider' import SelectField from 'material-ui/SelectField'; import MenuItem from 'material-ui/MenuItem'; import InputSize from './input-size'; - -import fs from 'fs' +import Checkbox from 'material-ui/Checkbox'; export default class ConfigPage extends Page { constructor(props) { super(props) this.setTitle('Rats filters'); this.options = {} + this.basicTypes = ['video', + 'audio', + 'pictures', + 'books', + 'application', + 'archive', + 'disc'] + this.contentType = this.basicTypes.slice(0) + this.descriptions = { + main: __('All'), + video: __('Video'), + audio: __('Audio/Music'), + books: __('Books'), + pictures: __('Pictures/Images'), + application: __('Apps/Games'), + archive: __('Archives'), + disc: __('Discs/ISO') + } } componentDidMount() { this.loadSettings() @@ -23,11 +40,19 @@ export default class ConfigPage extends Page { loadSettings() { window.torrentSocket.emit('config', window.customLoader((options) => { this.options = options; - console.log(this.options) + + if(this.options.filters && this.options.filters.contentType && this.options.filters.contentType.length > 0) + this.contentType = this.options.filters.contentType + this.forceUpdate(); })); } saveSettings() { + if(this.options.filters && this.basicTypes.length === this.contentType.length) + this.options.filters.contentType = null // обнуляем в случае если заданы все фильтры + else + this.options.filters.contentType = this.contentType + window.torrentSocket.emit('setConfig', this.options) this.settingsSavedMessage = true this.forceUpdate() @@ -164,6 +189,31 @@ export default class ConfigPage extends Page { } +
+
{__('disable some categories')}:
+ { + this.basicTypes.map(type => (= 0} + onCheck={e => { + if(e.target.checked) + { + this.contentType.push(type) + } + else + { + const index = this.contentType.indexOf(type) + this.contentType.splice(index, 1) + } + if(this.contentType.length == 0) + this.contentType = this.basicTypes.slice(0) + + this.forceUpdate() + }} + />)) + } +
+ { this.toRemoveProbably && this.toRemoveProbably > 0 ? diff --git a/src/background/spider.js b/src/background/spider.js index 3a99590..1443972 100644 --- a/src/background/spider.js +++ b/src/background/spider.js @@ -433,6 +433,12 @@ app.get('*', function(req, res) return false } + if(config.filters.contentType && Array.isArray(config.filters.contentType) && !config.filters.contentType.includes(torrent.contentType)) + { + console.log('ignore torrent', torrent.name, 'because type', torrent.contentType, 'not in:', config.filters.contentType) + return false + } + return true } diff --git a/translations/en.json b/translations/en.json index 73e01f1..9653ba4 100644 --- a/translations/en.json +++ b/translations/en.json @@ -178,6 +178,8 @@ "Pause torrent downloading": "Pause torrent downloading", "P2P torrents replication server": "P2P torrents replication server", "Enable torrents replication server for other rats clients (required for replication)": "Enable torrents replication server for other rats clients (required for replication)", - "* - 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", + "Discs/ISO": "Discs/ISO" } } \ No newline at end of file diff --git a/translations/ru.json b/translations/ru.json index 3956ac5..5204bf3 100644 --- a/translations/ru.json +++ b/translations/ru.json @@ -178,6 +178,8 @@ "Pause torrent downloading": "Пауза скачки торрента", "P2P torrents replication server": "Сервер репликация торрентов через p2p", "Enable torrents replication server for other rats clients (required for replication)": "Включить сервер репликации для остальных крысиных клиентов (необходим для репликации)", - "* - enabled means ignoring all adult content": "* - означает игнорирование всего контента для взрослых" + "* - enabled means ignoring all adult content": "* - означает игнорирование всего контента для взрослых", + "disable some categories": "отключить некоторые категории", + "Discs/ISO": "Диски/Образы" } } \ No newline at end of file diff --git a/translations/ua.json b/translations/ua.json index f41bd0d..0994830 100644 --- a/translations/ua.json +++ b/translations/ua.json @@ -178,6 +178,8 @@ "Pause torrent downloading": "Pause torrent downloading", "P2P torrents replication server": "P2P torrents replication server", "Enable torrents replication server for other rats clients (required for replication)": "Enable torrents replication server for other rats clients (required for replication)", - "* - 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", + "Discs/ISO": "Discs/ISO" } } \ No newline at end of file