diff --git a/alembic/versions/c72d305cf11e_download_settings.py b/alembic/versions/c72d305cf11e_download_settings.py new file mode 100644 index 00000000..6056c36c --- /dev/null +++ b/alembic/versions/c72d305cf11e_download_settings.py @@ -0,0 +1,29 @@ +"""Download settings + +Revision ID: c72d305cf11e +Revises: d2eace02f5b9 +Create Date: 2022-10-14 13:00:30.333384 + +""" +from alembic import op +from sqlalchemy.orm import Session + +# revision identifiers, used by Alembic. +revision = 'c72d305cf11e' +down_revision = 'd2eace02f5b9' +branch_labels = None +depends_on = None + + +def upgrade(): + bind = op.get_bind() + session = Session(bind=bind) + + session.execute('ALTER TABLE download ADD COLUMN settings JSONB') + + +def downgrade(): + bind = op.get_bind() + session = Session(bind=bind) + + session.execute('ALTER TABLE download DROP COLUMN IF EXISTS settings') diff --git a/app/src/api.js b/app/src/api.js index 96754ba9..c298826b 100644 --- a/app/src/api.js +++ b/app/src/api.js @@ -461,8 +461,8 @@ export async function getArchive(archiveId) { } } -export async function postDownload(urls, downloader, frequency, sub_downloader) { - let body = {urls: urls, downloader: downloader, frequency: frequency || null}; +export async function postDownload(urls, downloader, frequency, sub_downloader, excludedURLs) { + let body = {urls: urls, downloader: downloader, frequency: frequency || null, excluded_urls: excludedURLs}; if (sub_downloader) { body['sub_downloader'] = sub_downloader; } diff --git a/app/src/components/Common.js b/app/src/components/Common.js index c899c3dd..74909966 100644 --- a/app/src/components/Common.js +++ b/app/src/components/Common.js @@ -3,7 +3,6 @@ import {Card, Container, Image, Input, Pagination, Responsive, TableCell, TableR import {Link, NavLink} from "react-router-dom"; import Message from "semantic-ui-react/dist/commonjs/collections/Message"; import {useDownloaders, useHotspot, useThrottle} from "../hooks/customHooks"; -import {getSettings} from "../api"; import {darkTheme, SettingsContext, ThemeContext} from "../contexts/contexts"; import {Button, CardIcon, Form, Header, Icon, Menu, Popup, Statistic} from "./Theme"; diff --git a/app/src/components/Theme.js b/app/src/components/Theme.js index 778c3e55..9c9faad4 100644 --- a/app/src/components/Theme.js +++ b/app/src/components/Theme.js @@ -155,7 +155,6 @@ export function FormInput(props) { return } - export function Icon(props) { const {i} = useContext(ThemeContext); props = {...i, ...props}; diff --git a/app/src/components/Upload.js b/app/src/components/Upload.js index f7481262..cc7339a5 100644 --- a/app/src/components/Upload.js +++ b/app/src/components/Upload.js @@ -1,11 +1,11 @@ -import React, {useState} from "react"; +import React, {useContext, useState} from "react"; import {getDownloaders, postDownload} from "../api"; -import {frequencyOptions, rssFrequencyOptions, WROLModeMessage} from "./Common"; +import {frequencyOptions, HelpPopup, rssFrequencyOptions, WROLModeMessage} from "./Common"; import Icon from "semantic-ui-react/dist/commonjs/elements/Icon"; import Message from "semantic-ui-react/dist/commonjs/collections/Message"; import {ThemeContext} from "../contexts/contexts"; -import {Button, Form, FormInput, Header, Loader, TextArea} from "./Theme"; -import {ButtonGroup, FormDropdown} from "semantic-ui-react"; +import {Accordion, Button, Form, FormInput, Header, Loader, TextArea} from "./Theme"; +import {AccordionContent, AccordionTitle, FormDropdown} from "semantic-ui-react"; const validUrl = /^(http|https):\/\/[^ "]+$/; @@ -160,20 +160,31 @@ class ChannelDownload extends React.Component { } } +function ExcludedURLsLabel() { + const {t} = useContext(ThemeContext); + const excludedURLsHelp = + return
+ Excluded URLs + {excludedURLsHelp} +
+} + class RSSDownload extends ChannelDownload { constructor(props) { super(props); this.state = { - url: '', + disabled: false, + downloader: null, + downloaders: [], + error: null, + excludedURLs: '', frequency: 604800, pending: false, - disabled: false, ready: false, - error: null, - success: null, - downloaders: [], - downloader: null, sub_downloader: null, + success: null, + url: '', + activeIndex: -1, }; this.freqOptions = rssFrequencyOptions; } @@ -197,12 +208,12 @@ class RSSDownload extends ChannelDownload { handleSubmit = async (e) => { e.preventDefault(); this.setState({disabled: true, pending: true, success: null, error: null}); - const {url, frequency, sub_downloader} = this.state; + const {url, frequency, sub_downloader, excludedURLs} = this.state; if (!url) { this.setState({error: 'URL is required'}); return; } - let response = await postDownload(url, 'rss', frequency, sub_downloader); + let response = await postDownload(url, 'rss', frequency, sub_downloader, excludedURLs); if (response.status === 204) { this.setState({pending: false, disabled: false, success: true, url: '', ready: false}); } else { @@ -212,8 +223,19 @@ class RSSDownload extends ChannelDownload { } } + handleAdvancedClick = async (e, {index}) => { + const {activeIndex} = this.state; + const newIndex = activeIndex === index ? -1 : index; + this.setState({activeIndex: newIndex}); + } + + handleExcludedURLsChange = async (e, {value}) => { + e.preventDefault(); + this.setState({excludedURLs: value}); + } + render() { - const {ready, disabled, url, error, frequency, pending, success} = this.state; + const {ready, disabled, url, error, frequency, pending, success, activeIndex, excludedURLs} = this.state; const buttonDisabled = !ready || disabled; const onceMessage = ( @@ -253,6 +275,25 @@ class RSSDownload extends ChannelDownload { placeholder='Select a downloader' onChange={this.handleInputChange} /> + + + + Advanced + + + } + placeholder='example.com,example.org' + value={excludedURLs} + error={error} + onChange={this.handleExcludedURLsChange} + /> + +