mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-12-02 20:59:56 -05:00
Displaying error when video file name format is invalid.
This commit is contained in:
parent
b7d163e7ff
commit
bf29bdcff7
12 changed files with 201 additions and 35 deletions
|
|
@ -1499,3 +1499,8 @@ export async function postRestart() {
|
|||
}
|
||||
return null
|
||||
}
|
||||
|
||||
export async function postVideoFileFormat(video_file_format) {
|
||||
const body = {video_file_format};
|
||||
return await apiPost(`${API_URI}/videos/file_format`, body);
|
||||
}
|
||||
|
|
@ -1607,7 +1607,7 @@ export function WarningMessage({children, size = null, icon = 'exclamation'}) {
|
|||
}
|
||||
|
||||
export function ErrorMessage({children, size = null, icon = 'exclamation'}) {
|
||||
return <Message error icon size={size}>
|
||||
return <Message negative icon size={size}>
|
||||
<SIcon name={icon}/>
|
||||
<Message.Content>{children}</Message.Content>
|
||||
</Message>
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ import {FileRowTagIcon, FilesView} from "./Files";
|
|||
import Grid from "semantic-ui-react/dist/commonjs/collections/Grid";
|
||||
import Icon from "semantic-ui-react/dist/commonjs/elements/Icon";
|
||||
import {Button, Card, Header, Loader, Placeholder, Popup, Segment, Statistic, StatisticGroup} from "./Theme";
|
||||
import {deleteVideos, fetchVideoDownloaderConfig, saveVideoDownloaderConfig} from "../api";
|
||||
import {deleteVideos, fetchVideoDownloaderConfig, postVideoFileFormat, saveVideoDownloaderConfig} from "../api";
|
||||
import {Media, QueryContext, ThemeContext} from "../contexts/contexts";
|
||||
import _ from "lodash";
|
||||
import {defaultFileOrder, defaultSearchOrder} from "./Vars";
|
||||
|
|
@ -222,6 +222,29 @@ function VideosPage() {
|
|||
</>
|
||||
}
|
||||
|
||||
function VideoFileNameForm({form}) {
|
||||
const [message, setMessage] = React.useState(null);
|
||||
|
||||
const onChange = async (value) => {
|
||||
const response = await postVideoFileFormat(value);
|
||||
const {error, preview} = await response.json();
|
||||
if (error) {
|
||||
setMessage({content: error, header: 'Invalid File Name', negative: true});
|
||||
} else {
|
||||
setMessage({content: preview, header: 'File Name Preview', positive: true});
|
||||
}
|
||||
}
|
||||
|
||||
return <InputForm
|
||||
form={form}
|
||||
name='file_name_format'
|
||||
path='yt_dlp_options.file_name_format'
|
||||
label='Video File Format'
|
||||
onChange={onChange}
|
||||
message={message}
|
||||
/>
|
||||
}
|
||||
|
||||
function VideosSettings() {
|
||||
useTitle('Videos Settings');
|
||||
|
||||
|
|
@ -255,62 +278,55 @@ function VideosSettings() {
|
|||
|
||||
<Form>
|
||||
<Grid>
|
||||
<Grid.Row>
|
||||
<Grid.Column>
|
||||
<Grid.Row columns={2}>
|
||||
<Grid.Column mobile={16} computer={8}>
|
||||
<VideoResolutionSelectorForm
|
||||
form={form}
|
||||
name='video_resolutions'
|
||||
path='video_resolutions'
|
||||
/>
|
||||
</Grid.Column>
|
||||
</Grid.Row>
|
||||
<Grid.Row>
|
||||
<Grid.Column>
|
||||
<InputForm
|
||||
form={form}
|
||||
name='file_name_format'
|
||||
path='yt_dlp_options.file_name_format'
|
||||
label='Video File Format'
|
||||
/>
|
||||
<Grid.Column mobile={16} computer={8}>
|
||||
<VideoFileNameForm form={form}/>
|
||||
</Grid.Column>
|
||||
</Grid.Row>
|
||||
<Grid.Row>
|
||||
<Grid.Column>
|
||||
<Grid.Row columns={2}>
|
||||
<Grid.Column mobile={16} computer={8}>
|
||||
<ToggleForm
|
||||
form={form}
|
||||
label='Do not overwrite existing files'
|
||||
name='nooverwrites'
|
||||
path='yt_dlp_options.nooverwrites'
|
||||
icon='file video'
|
||||
/>
|
||||
</Grid.Column>
|
||||
</Grid.Row>
|
||||
<Grid.Row>
|
||||
<Grid.Column>
|
||||
<Grid.Column mobile={16} computer={8}>
|
||||
<ToggleForm
|
||||
form={form}
|
||||
label='Download automatic subtitles'
|
||||
name='writeautomaticsub'
|
||||
path='yt_dlp_options.writeautomaticsub'
|
||||
icon='closed captioning'
|
||||
/>
|
||||
</Grid.Column>
|
||||
</Grid.Row>
|
||||
<Grid.Row>
|
||||
<Grid.Column>
|
||||
<Grid.Column mobile={16} computer={8}>
|
||||
<ToggleForm
|
||||
form={form}
|
||||
label='Download subtitles'
|
||||
name='writesubtitles'
|
||||
path='yt_dlp_options.writesubtitles'
|
||||
icon='closed captioning outline'
|
||||
/>
|
||||
</Grid.Column>
|
||||
</Grid.Row>
|
||||
<Grid.Row>
|
||||
<Grid.Column>
|
||||
<Grid.Column mobile={16} computer={8}>
|
||||
<ToggleForm
|
||||
form={form}
|
||||
label='Download thumbnail'
|
||||
name='writethumbnail'
|
||||
path='yt_dlp_options.writethumbnail'
|
||||
icon='image'
|
||||
/>
|
||||
</Grid.Column>
|
||||
</Grid.Row>
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
import React from "react";
|
||||
import _ from "lodash";
|
||||
import {HelpPopup, RequiredAsterisk, Toggle, validURL, validURLs} from "../components/Common";
|
||||
import {FormInput, TextArea} from "../components/Theme";
|
||||
import {FormInput, Icon, TextArea} from "../components/Theme";
|
||||
import Message from "semantic-ui-react/dist/commonjs/collections/Message";
|
||||
|
||||
|
||||
async function asyncNoOp() {
|
||||
|
|
@ -158,6 +159,8 @@ export function useForm({
|
|||
|
||||
// Trigger validation after a delay
|
||||
debouncedValidate(path, value);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
const addValidator = (path, validator) => {
|
||||
|
|
@ -207,7 +210,7 @@ export function useForm({
|
|||
return [inputProps, inputAttrs]
|
||||
}
|
||||
|
||||
const getInputProps = ({name, validator, path, required = false, type = 'text'}) => {
|
||||
const getInputProps = ({name, validator, path, required = false, type = 'text', onChange = null}) => {
|
||||
// Props for <input/>
|
||||
path = path || name;
|
||||
|
||||
|
|
@ -218,11 +221,19 @@ export function useForm({
|
|||
|
||||
const [customProps, inputAttrs] = getCustomProps({name, validator, path, type, required});
|
||||
|
||||
const localHandleInputEvent = async (e) => {
|
||||
if (e) e.preventDefault();
|
||||
const value = handleInputEvent(e);
|
||||
if (onChange) {
|
||||
await onChange(value);
|
||||
}
|
||||
}
|
||||
|
||||
// Attributes that should be passed as properties to the input.
|
||||
const inputProps = {
|
||||
...customProps,
|
||||
name: name,
|
||||
onChange: handleInputEvent,
|
||||
onChange: localHandleInputEvent,
|
||||
error: errors[path] || null,
|
||||
required: required ? null : undefined,
|
||||
}
|
||||
|
|
@ -280,10 +291,21 @@ export function InputForm({
|
|||
helpPosition = 'top',
|
||||
extraInputProps = {},
|
||||
disabled = false,
|
||||
onChange = null,
|
||||
message = null,
|
||||
}) {
|
||||
const [inputProps, inputAttrs] = form.getInputProps({name, path, validator, type, required});
|
||||
const [inputProps, inputAttrs] = form.getInputProps({name, path, validator, type, required, onChange});
|
||||
inputProps.disabled = disabled || inputProps.disabled;
|
||||
|
||||
let messageElm = null;
|
||||
if (message && message.positive) {
|
||||
messageElm = <Message {...message} positive/>;
|
||||
} else if (message && message.negative) {
|
||||
messageElm = <Message {...message}/>;
|
||||
} else if (message) {
|
||||
messageElm = <Message {...message}/>;
|
||||
}
|
||||
|
||||
return <>
|
||||
<label for={`${name}_input`}>
|
||||
<b>{label} {required && <RequiredAsterisk/>}</b>
|
||||
|
|
@ -301,6 +323,7 @@ export function InputForm({
|
|||
>
|
||||
<input {...extraInputProps} {...inputProps}/>
|
||||
</FormInput>
|
||||
{messageElm}
|
||||
</>
|
||||
}
|
||||
|
||||
|
|
@ -403,11 +426,13 @@ export function UrlsTextarea({name = 'urls', required, form}) {
|
|||
</FormInput>
|
||||
}
|
||||
|
||||
export function ToggleForm({form, name, label, path}) {
|
||||
export function ToggleForm({form, name, label, path, icon = null, iconSize = 'big'}) {
|
||||
const [inputProps, inputAttrs] = form.getCustomProps({name, path})
|
||||
|
||||
const iconElm = icon ? <Icon size={iconSize} name={icon}/> : null;
|
||||
return <FormInput
|
||||
label={label}>
|
||||
{iconElm}
|
||||
<Toggle
|
||||
disabled={form.disabled}
|
||||
name={name}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue