diff --git a/alembic/versions/8d0d81bc9c34_channel_channel_downloads.py b/alembic/versions/8d0d81bc9c34_channel_channel_downloads.py new file mode 100644 index 00000000..799e8b12 --- /dev/null +++ b/alembic/versions/8d0d81bc9c34_channel_channel_downloads.py @@ -0,0 +1,55 @@ +"""Channel.channel_downloads + +Revision ID: 8d0d81bc9c34 +Revises: 00f11f309c53 +Create Date: 2024-06-25 22:13:23.885687 + +""" +import os + +from alembic import op +from sqlalchemy.ext.declarative import declarative_base +from sqlalchemy.orm import Session + +# revision identifiers, used by Alembic. +revision = '8d0d81bc9c34' +down_revision = '00f11f309c53' +branch_labels = None +depends_on = None + +DOCKERIZED = True if os.environ.get('DOCKER', '').lower().startswith('t') else False + +Base = declarative_base() + + +def upgrade(): + bind = op.get_bind() + session = Session(bind=bind) + + session.execute('ALTER TABLE download ADD CONSTRAINT download_url_unique UNIQUE (url)') + session.execute(''' + CREATE TABLE channel_download ( + channel_id INTEGER REFERENCES channel (id), + download_url TEXT REFERENCES download (url), + primary key (channel_id, download_url) + )''') + + # Migration is separated for testing. See `test_channel_channel_downloads_migration` + from wrolpi.migration import migrate_channel_downloads + migrate_channel_downloads(session) + + session.execute('ALTER TABLE channel DROP COLUMN IF EXISTS match_regex') + session.execute('ALTER TABLE channel DROP COLUMN IF EXISTS download_frequency') + + if not DOCKERIZED: + session.execute('ALTER TABLE public.channel_download OWNER TO wrolpi') + + +def downgrade(): + bind = op.get_bind() + session = Session(bind=bind) + + session.execute('DROP TABLE IF EXISTS channel_download') + session.execute('ALTER TABLE channel ADD COLUMN IF NOT EXISTS match_regex TEXT') + session.execute('ALTER TABLE channel ADD COLUMN IF NOT EXISTS download_frequency INTEGER') + session.execute('ALTER TABLE download DROP CONSTRAINT IF EXISTS download_url_unique') diff --git a/app/src/Tags.js b/app/src/Tags.js index cdee1491..9a6eaeea 100644 --- a/app/src/Tags.js +++ b/app/src/Tags.js @@ -314,7 +314,8 @@ export function AddTagsButton({ selectedTagNames = [], onToggle = _.noop, onAdd = _.noop, - onRemove = _.noop + onRemove = _.noop, + limit = null, }) { // A button which displays a modal in which the user can add or remove tags. @@ -334,6 +335,9 @@ export function AddTagsButton({ setLoading(true); try { const newTags = [...localTags, name]; + if (limit !== null && newTags.length > limit) { + return; + } setLocalTags(newTags); onToggle(newTags); onAdd(name); @@ -375,6 +379,7 @@ export function AddTagsButton({ const selectedTagsGroup = ; const unusedTags = _.difference(tagNames, localTags); const unusedTagsGroup = ; + const emptySelectedTags = limit === 1 ? 'Add only one tag below' : 'Add one or more tags below'; return <> + + + + setDownloadModalOpen(false)}> + +
New Channel Download
+ setDownloadModalOpen(false)} + /> +
+
+ + + } +
{channel.statistics && }
} +export function ChannelDownloadForm({channel_id, afterSave, closeModal, download}) { + download = download || {}; + channel_id = download ? download.channel_id || channel_id : channel_id; + const editing = download && !_.isEmpty(download); + + const settings = download.settings ? download.settings : {}; + const oldTagNames = download && download.settings && download.settings.tag_names ? download.settings.tag_names : []; + const [state, setState] = React.useState({ + url: download ? download.url : '', + frequency: download.frequency ? download.frequency : 604800, + title_match: settings.title_match ? settings.title_match : '', + title_exclude: settings.title_exclude ? settings.title_exclude : '', + }) + const [disabled, setDisabled] = React.useState(useWROLMode()); + const [loading, setLoading] = React.useState(false); + const [urlValid, setUrlValid] = React.useState(true); + const [tagNames, setTagNames] = React.useState(oldTagNames); + + const handleInputChange = (e, {name, value}) => { + if (e) { + e.preventDefault(); + } + if (name === 'url') { + setUrlValid(validURL(value)); + } + setState({...state, [name]: value}); + } + + const handleSubmit = async () => { + setLoading(true); + setDisabled(true); + try { + let response; + if (editing) { + response = await updateChannelDownload( + channel_id, + download.id, + state.url, + state.frequency, + state.title_match, + state.title_exclude, + tagNames, + ); + } else { + response = await createChannelDownload( + channel_id, + state.url, + state.frequency, + state.title_match, + state.title_exclude, + tagNames, + ); + } + if (!response.ok) { + throw 'Creating download failed'; + } + if (afterSave) { + await afterSave(); + } + } finally { + setLoading(false); + setDisabled(false); + } + } + + const handleClose = (e) => { + if (e) e.preventDefault(); + closeModal(); + } + + const handleDelete = async () => { + await deleteDownload(download.id); + if (afterSave) { + afterSave(); + } + if (closeModal) { + closeModal(); + } + }; + + const handleAddTag = (tagName) => { + setTagNames([...tagNames, tagName]); + } + + const handleUntag = (tagName) => { + setTagNames(tagNames.filter(i => i !== tagName)); + } + + const deleteDownloadButton = Delete; + + return
+ {loading && } + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + {editing && deleteDownloadButton} + + + + + +
+} + export function ChannelEditPage(props) { return ; } @@ -463,7 +609,7 @@ function ChannelRow({channel}) { {channel.video_count} - {channel.url && channel.download_frequency ? secondsToFrequency(channel.download_frequency) : null} + {channel.url && channel.minimum_frequency ? secondsToFrequency(channel.minimum_frequency) : null} {channel.size ? humanFileSize(channel.size) : null} @@ -532,7 +678,7 @@ export function ChannelsPage() { const headers = [ {key: 'name', text: 'Name', sortBy: 'name', width: 8}, {key: 'video_count', text: 'Videos', sortBy: 'video_count', width: 2}, - {key: 'download_frequency', text: 'Download Frequency', sortBy: 'download_frequency', width: 2}, + {key: 'download_frequency', text: 'Download Frequency', sortBy: 'minimum_frequency', width: 2}, {key: 'size', text: 'Size', sortBy: 'size', width: 2}, {key: 'manage', text: 'Manage', width: 2}, ]; diff --git a/app/src/components/Common.js b/app/src/components/Common.js index fda3753b..f032ef3c 100644 --- a/app/src/components/Common.js +++ b/app/src/components/Common.js @@ -735,23 +735,23 @@ export function CardPoster({to, file}) { } } -export function HelpPopup({icon, size, content, position, iconSize = 'small'}) { +export function HelpPopup({icon = 'question', size = null, content, position = 'left center', iconSize = 'small'}) { return } /> } -export function HelpHeader({icon, headerSize, iconSize, headerContent, popupContent}) { +export function HelpHeader({icon, headerSize = 'h2', iconSize, headerContent, popupContent, popupPosition = 'top center'}) { return
-
{headerContent}
+
{headerContent}
- - + +
} @@ -1788,3 +1788,9 @@ export function Breadcrumbs({crumbs, size = undefined}) { ))} } + +const validUrlRegex = /^(http|https):\/\/[^ "]+$/; + +export function validURL(url) { + return !(url && !validUrlRegex.test(url)); +} \ No newline at end of file diff --git a/app/src/components/Download.js b/app/src/components/Download.js index 19fb7f92..fa8b82e4 100644 --- a/app/src/components/Download.js +++ b/app/src/components/Download.js @@ -1,6 +1,14 @@ import React, {useContext, useState} from "react"; import {getDownloaders, postDownload} from "../api"; -import {APIButton, DirectorySearch, frequencyOptions, HelpPopup, rssFrequencyOptions, WROLModeMessage} from "./Common"; +import { + APIButton, + DirectorySearch, + frequencyOptions, + HelpPopup, + rssFrequencyOptions, + validURL, + 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"; @@ -11,8 +19,6 @@ import {TagsSelector} from "../Tags"; import {toast} from "react-semantic-toasts-2"; import Grid from "semantic-ui-react/dist/commonjs/collections/Grid"; -const validUrl = /^(http|https):\/\/[^ "]+$/; - class Downloader extends React.Component { constructor(props) { super(props); @@ -58,9 +64,7 @@ class Downloader extends React.Component { let urls = this.state.urls.split(/\r?\n/); let valid = true; urls.forEach((url) => { - if (valid && url && !validUrl.test(url)) { - valid = false; - } + valid = validURL(url); }) this.setState({valid}); } @@ -192,7 +196,7 @@ class ChannelDownload extends React.Component { handleUrlChange = (e, {value}) => { e.preventDefault(); - let ready = value && validUrl.test(value); + let ready = value && validURL(value); this.setState({url: value, ready, success: false}); } diff --git a/app/src/components/Videos.js b/app/src/components/Videos.js index 814caf7a..8b74a14c 100644 --- a/app/src/components/Videos.js +++ b/app/src/components/Videos.js @@ -242,7 +242,7 @@ function VideosStatistics() { ]; const commentsNames = [ {key: 'have_comments', label: 'Have Comments'}, - {key: 'no_comments', label: 'Missing Comments'}, + {key: 'missing_comments', label: 'Missing Comments'}, {key: 'failed_comments', label: 'Failed Comments'}, ]; const historicalNames = [ diff --git a/app/src/components/admin/Downloads.js b/app/src/components/admin/Downloads.js index 9df32aa3..3d0e0161 100644 --- a/app/src/components/admin/Downloads.js +++ b/app/src/components/admin/Downloads.js @@ -4,6 +4,7 @@ import { deleteDownload, deleteOnceDownloads, killDownload, + putDownload, restartDownload, retryOnceDownloads } from "../../api"; @@ -12,13 +13,18 @@ import { APIButton, DisableDownloadsToggle, ErrorMessage, + frequencyOptions, isoDatetimeToElapsedPopup, secondsToFrequency, useTitle, + validURL, WROLModeMessage } from "../Common"; import { Button as SButton, + Dimmer, + Dropdown, + Grid, Label, Loader, PlaceholderLine, @@ -29,9 +35,23 @@ import { TableHeaderCell, TableRow } from "semantic-ui-react"; -import {Button, Header, Modal, ModalActions, ModalContent, ModalHeader, Placeholder, Segment, Table} from "../Theme"; -import {useDownloads} from "../../hooks/customHooks"; +import { + Button, + Form, + FormField, + FormInput, + Header, + Modal, + ModalActions, + ModalContent, + ModalHeader, + Placeholder, + Segment, + Table +} from "../Theme"; +import {useDownloads, useWROLMode} from "../../hooks/customHooks"; import {toast} from "react-semantic-toasts-2"; +import {ChannelDownloadForm} from "../Channels"; function ClearDownloadsButton({callback}) { async function localClearDownloads() { @@ -91,11 +111,134 @@ function DeleteOnceDownloadsButton({callback}) { >Delete } + +export function DownloadEditForm({afterSave, closeModal, download}) { + const [state, setState] = React.useState({ + url: download.url || '', + frequency: download.frequency, + excluded_urls: download.excluded_urls || '', + }) + const [disabled, setDisabled] = React.useState(useWROLMode()); + const [loading, setLoading] = React.useState(false); + const [urlValid, setUrlValid] = React.useState(true); + + const handleInputChange = (e, {name, value}) => { + if (e) { + e.preventDefault(); + } + if (name === 'url') { + setUrlValid(validURL(value)); + } + setState({...state, [name]: value}); + } + + const handleSubmit = async () => { + setLoading(true); + setDisabled(true); + try { + const response = await putDownload( + [state.url], + download.id, + download.downloader, + download.sub_downloader, + state.frequency, + state.excluded_urls, + ); + if (!response.ok) { + throw 'Updating download failed'; + } + } finally { + setLoading(false); + setDisabled(false); + if (afterSave) { + afterSave(); + } + } + } + + const handleClose = (e) => { + if (e) e.preventDefault(); + closeModal(); + } + + const handleDelete = async () => { + await deleteDownload(download.id); + if (afterSave) { + afterSave(); + } + if (closeModal) { + closeModal(); + } + }; + + const deleteDownloadButton = Delete; + + return
+ {loading && } + + + + + + + + + + + + + + + + + + + + {deleteDownloadButton} + + + + + +
+} + + class RecurringDownloadRow extends React.Component { constructor(props) { super(props); this.state = { errorModalOpen: false, + editModalOpen: false, } } @@ -133,7 +276,17 @@ class RecurringDownloadRow extends React.Component { } render() { - let {url, frequency, last_successful_download, status, location, next_download, error} = this.props; + let { + url, + frequency, + last_successful_download, + status, + location, + next_download, + error, + downloader, + channel_id + } = this.props; const {errorModalOpen} = this.state; const link = location ? @@ -167,6 +320,10 @@ class RecurringDownloadRow extends React.Component { /> ; + const editButton = <> +