;
return
}
export function RSSDownloadForm({download, submitter, onDelete, onCancel, actions, clearOnSuccess = true}) {
const [showMessage, setShowMessage] = React.useState(false);
const [config, setConfig] = React.useState(null);
const [isConfigLoaded, setIsConfigLoaded] = React.useState(false);
const [userChangedResolutions, setUserChangedResolutions] = React.useState(false);
const [defaultVideoFormat, setDefaultVideoFormat] = useLocalStorage('video_format', defaultVideoFormatOption);
submitter = submitter || (async (formData) => {
const downloadData = {
destination: formData.destination,
downloader: formData.downloader,
frequency: formData.frequency,
settings: formData.settings,
sub_downloader: formData.sub_downloader,
tag_names: formData.tag_names || [],
urls: [formData.url],
}
await postDownload(downloadData);
});
// Use config video resolutions if available, otherwise use default
const configResolutions = config && config.video_resolutions ? config.video_resolutions : defaultVideoResolutionOptions;
const emptyFormData = {
destination: null,
downloader: Downloaders.RSS,
frequency: weeklyOption.value,
sub_downloader: null,
settings: {
excluded_urls: null,
title_exclude: null,
title_include: null,
video_resolutions: configResolutions,
video_format: defaultVideoFormat,
audio_only: false,
audio_format: defaultAudioFormatOption,
writesubtitles: false,
writeautomaticsub: false,
writethumbnail: false,
writeinfojson: false,
yt_dlp_extra_args: '',
sleep_requests: '',
user_agent: '',
},
tag_names: [],
url: '',
};
const form = useForm({
submitter,
defaultFormData: mergeDeep(emptyFormData, download),
emptyFormData,
clearOnSuccess,
onSuccess: async () => setShowMessage(true),
});
// Fetch global defaults to pre-fill the form
React.useEffect(() => {
const fetchDefaults = async () => {
try {
const defaults = await fetchVideoDownloadDefaults();
setConfig(defaults);
setIsConfigLoaded(true);
if (defaults && download) {
for (const [key, value] of Object.entries(defaults)) {
if (key === 'continue_dl' || key === 'nooverwrites') continue;
if (download.settings?.[key] === undefined || download.settings?.[key] === null) {
form.setValue(`settings.${key}`, value);
}
}
} else if (defaults) {
const downloadHasResolutions = download?.settings?.video_resolutions?.length > 0;
for (const [key, value] of Object.entries(defaults)) {
if (key === 'continue_dl' || key === 'nooverwrites') continue;
if (key === 'video_resolutions' && (userChangedResolutions || downloadHasResolutions)) continue;
if (key === 'video_format') continue;
form.setValue(`settings.${key}`, value);
}
if (!userChangedResolutions && !downloadHasResolutions && defaults.video_resolutions) {
form.setValue('settings.video_resolutions', defaults.video_resolutions);
}
}
} catch (error) {
console.error('Failed to fetch video download defaults:', error);
setIsConfigLoaded(true);
}
};
fetchDefaults();
}, []);
React.useEffect(() => {
const {video_format} = form.formData.settings;
if (video_format && video_format !== defaultVideoFormat) {
setDefaultVideoFormat(video_format);
}
}, [form.formData]);
// Default to "new" download buttons.
actions = actions || DownloadFormButtons;
const actionsElm = actions({onDelete, onCancel, form});
let downloaderRows;
if (form.formData.sub_downloader === Downloaders.Video) {
downloaderRows = <>
{form.formData?.settings?.audio_only
?
:
setUserChangedResolutions(true)}
/>
}
>;
} else if (form.formData.sub_downloader === Downloaders.Archive) {
downloaderRows =
;
}
return
}
export function EditRSSDownloadForm({download, onDelete, onCancel, actions = EditDownloadFormButtons}) {
const submitter = async (formData) => {
const downloadData = {
collection_id: download.collection_id,
destination: formData.destination,
downloader: formData.downloader,
frequency: formData.frequency,
settings: formData.settings,
sub_downloader: formData.sub_downloader,
tag_names: formData.tag_names || [],
urls: [formData.url,],
}
await putDownload(download.id, downloadData);
}
return
}
export function EditZimDownloadForm({download, onDelete, onCancel, actions = EditDownloadFormButtons}) {
const submitter = async (formData) => {
const downloadData = {
collection_id: download.collection_id,
downloader: formData.downloader,
frequency: formData.frequency,
settings: formData.settings,
sub_downloader: formData.sub_downloader,
tag_names: formData.tag_names,
urls: [formData.url,],
}
await putDownload(download.id, downloadData);
}
const [showMessage, setShowMessage] = React.useState(false);
const emptyFormData = {
downloader: Downloaders.RSS,
frequency: weeklyOption.value,
sub_downloader: null,
tag_names: [],
url: '',
};
const form = useForm({
submitter,
defaultFormData: mergeDeep(emptyFormData, download),
emptyFormData,
onSuccess: async () => setShowMessage(true),
});
// Default to "new" download buttons.
actions = actions || DownloadFormButtons;
const actionsElm = actions({onDelete, onCancel, form});
return
}
export function FilesDownloadForm({
download,
submitter,
onCancel,
actions = DownloadFormButtons,
clearOnSuccess = true,
}) {
const [showMessage, setShowMessage] = React.useState(false);
submitter = submitter || (async (formData) => {
const downloadData = {
downloader: Downloaders.File,
tag_names: formData.tag_names,
destination: formData.destination,
urls: formData.urls.split(/\r?\n/),
settings: formData.settings,
}
await postDownload(downloadData);
});
const emptyFormData = {
destination: null,
tag_names: [],
urls: '',
settings: {
skip_already_downloaded: false,
},
};
const form = useForm({
submitter,
defaultFormData: mergeDeep(emptyFormData, download),
emptyFormData,
clearOnSuccess,
onSuccess: async () => setShowMessage(true),
});
const actionsElm = actions({onCancel, form});
return
}
const suffixValidator = (value) => {
const error = commaSeparatedValidator(value);
if (error) {
return error;
}
const suffixes = value.split(',');
for (const suffix of suffixes) {
if (!suffix.startsWith('.')) {
return 'Suffix must start with .';
}
if (suffix.length === 1) {
return 'Suffix must have characters after .';
}
}
}
export function SuffixFormInput({form, name = 'suffix', path = 'settings.suffix'}) {
return
}
export function ScrapeFilesDownloadForm({
download,
submitter,
clearOnSuccess,
onDelete,
onCancel,
onSuccess,
actions = DownloadFormButtons,
singleDownload = false,
}) {
const [showMessage, setShowMessage] = React.useState(false);
submitter = submitter || (async (formData) => {
const downloadData = {
downloader: Downloaders.ScrapeHtml,
sub_downloader: Downloaders.File,
tag_names: formData.tag_names || [],
destination: formData.destination,
urls: formData.urls.split(/\r?\n/),
settings: formData.settings,
}
await postDownload(downloadData);
});
const emptyFormData = {
destination: null,
tag_names: [],
urls: '',
settings: {
depth: 1,
max_pages: 1,
suffix: '',
}
};
const localOnSuccess = async () => {
setShowMessage(true);
if (onSuccess) {
onSuccess();
}
}
const form = useForm({
submitter,
defaultFormData: mergeDeep(emptyFormData, download),
emptyFormData,
clearOnSuccess,
onSuccess: localOnSuccess,
});
const urlInput = singleDownload ?
: ;
// Default to "new" download buttons.
actions = actions || DownloadFormButtons;
const actionsElm = actions({onDelete, onCancel, form});
return
}
export function EditScrapeFilesDownloadForm({download, onDelete, onCancel, onSuccess}) {
const submitter = async (formData) => {
const downloadData = {
collection_id: download.collection_id,
downloader: Downloaders.ScrapeHtml,
sub_downloader: Downloaders.File,
tag_names: formData.tag_names || [],
destination: formData.destination,
urls: [formData.url],
settings: formData.settings,
}
await putDownload(download.id, downloadData);
};
return
}
export function DownloadMenu({onOpen, disabled, initialDownloader, initialUrls}) {
// initialDownloader and initialUrls support the deep-link flow used by the
// WROLPi browser extension's "Configure Download" button: visiting
// `/?downloader=archive&download_url=...` pre-selects a form and pre-fills
// its URLs textarea via DashboardPage.Getters.
const [downloader, setDownloader] = useState(initialDownloader || undefined);
const localOnOpen = (name) => {
setDownloader(name);
if (onOpen) {
onOpen(name);
}
}
let body = (<>