Allowing user to configure collection download destination directories, as well as directories in the file structure. This will allow sorting archives by destination year, for example.

This commit is contained in:
Roland 2025-12-22 17:56:35 -07:00
parent 3f4d5798e2
commit 1ebcae0965
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
21 changed files with 780 additions and 160 deletions

View file

@ -43,14 +43,18 @@ import {
import {
deleteArchives,
deleteDomain,
fetchArchiveDownloaderConfig,
generateArchiveScreenshot,
getCollectionTagInfo,
postArchiveFileFormat,
postDownload,
refreshDomain,
tagDomain,
tagFileGroup,
untagFileGroup
untagFileGroup,
updateArchiveDownloaderConfig,
} from "../api";
import {InputForm, useForm} from "../hooks/useForm";
import {CollectionTagModal} from "./collections/CollectionTagModal";
import {Link, Route, Routes, useLocation, useNavigate, useParams} from "react-router";
import Message from "semantic-ui-react/dist/commonjs/collections/Message";
@ -658,9 +662,67 @@ export function DomainEditPage() {
</>;
}
function ArchiveFileNameForm({form}) {
const [message, setMessage] = React.useState(null);
const onChange = async (value) => {
const response = await postArchiveFileFormat(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});
}
}
const label = <InfoHeader
headerSize='h5'
headerContent='Archive File Format'
popupProps={{wide: 'very', position: 'top left'}}
popupContent={<>
<p>Variables:</p>
<ul>
<li><code>%(title)s</code> - Page title</li>
<li><code>%(download_datetime)s</code> - Full datetime (YYYY-MM-DD-HH-MM-SS)</li>
<li><code>%(download_date)s</code> - Date only (YYYY-MM-DD)</li>
<li><code>%(download_year)s</code> - Year</li>
<li><code>%(download_month)s</code> - Month (zero-padded)</li>
<li><code>%(download_day)s</code> - Day (zero-padded)</li>
<li><code>%(domain)s</code> - Domain name</li>
</ul>
<p>Subdirectories supported: <code>%(download_year)s/%(title)s</code></p>
</>}
/>;
return <InputForm
form={form}
name='file_name_format'
path='file_name_format'
label={label}
onChange={onChange}
message={message}
/>
}
function ArchiveSettingsPage() {
useTitle('Archive Settings');
const {t} = React.useContext(ThemeContext);
const emptyFormData = {
file_name_format: '%(download_datetime)s_%(title)s',
};
const configSubmitter = async () => {
return await updateArchiveDownloaderConfig(configForm.formData);
};
const configForm = useForm({
fetcher: fetchArchiveDownloaderConfig,
submitter: configSubmitter,
emptyFormData,
});
const urlClipboardButton = <APIButton
icon='copy'
onClick={() => navigator.clipboard.writeText(API_ARCHIVE_UPLOAD_URI)}
@ -675,29 +737,56 @@ function ArchiveSettingsPage() {
/>;
return <PageContainer>
<Header as='h1'>SingleFile Browser Extension</Header>
<Segment>
<Header as='h3'>Archive Downloader Config</Header>
<p {...t}>
These are the settings necessary to configure the <a
href="https://github.com/gildas-lormeau/SingleFile?tab=readme-ov-file#install">SingleFile Browser
Extension</a> to automatically upload to your WROLPi.
</p>
<Form>
<Grid>
<GridRow columns={1}>
<GridColumn mobile={16} computer={8}>
<ArchiveFileNameForm form={configForm}/>
</GridColumn>
</GridRow>
<GridRow columns={1}>
<GridColumn textAlign='right'>
<APIButton
disabled={configForm.disabled || !configForm.ready}
type='submit'
style={{marginTop: '0.5em'}}
onClick={configForm.onSubmit}
id='archive_settings_save_button'
>Save</APIButton>
</GridColumn>
</GridRow>
</Grid>
</Form>
</Segment>
<label {...t}>Upload URL</label>
<Input fluid
value={API_ARCHIVE_UPLOAD_URI}
label={urlClipboardButton}
/>
<label {...t}>Data Field Name</label>
<Input fluid
value='singlefile_contents'
label={dataFieldNameClipboardButton}
/>
<label {...t}>URL Field Name</label>
<Input fluid
value='url'
label={urlFieldNameClipboardButton}
/>
<Segment>
<Header as='h3'>SingleFile Browser Extension</Header>
<p {...t}>
These are the settings necessary to configure the <a
href="https://github.com/gildas-lormeau/SingleFile?tab=readme-ov-file#install">SingleFile Browser
Extension</a> to automatically upload to your WROLPi.
</p>
<label {...t}>Upload URL</label>
<Input fluid
value={API_ARCHIVE_UPLOAD_URI}
label={urlClipboardButton}
/>
<label {...t}>Data Field Name</label>
<Input fluid
value='singlefile_contents'
label={dataFieldNameClipboardButton}
/>
<label {...t}>URL Field Name</label>
<Input fluid
value='url'
label={urlFieldNameClipboardButton}
/>
</Segment>
</PageContainer>
}

View file

@ -759,6 +759,7 @@ export function InfoPopup({
iconSize = null,
header = '',
iconStyle = {marginLeft: '0.25em', marginRight: '0.25em', marginTop: '-0.5em'},
...props
}) {
const trigger = <Icon link name={icon} size={iconSize} style={iconStyle}/>;
return <Popup
@ -768,6 +769,7 @@ export function InfoPopup({
header={header || null}
trigger={trigger}
hoverable={true}
{...props}
/>
}
@ -778,6 +780,7 @@ export function InfoHeader({
headerContent,
popupContent,
popupPosition = null,
popupProps = {},
for_ = null,
required = false,
...props
@ -787,7 +790,7 @@ export function InfoHeader({
<Header as={headerSize}>{headerContent} {required && <RequiredAsterisk/>}</Header>
</label>
<span>
<InfoPopup content={popupContent} iconSize={iconSize} icon={icon} position={popupPosition}/>
<InfoPopup content={popupContent} iconSize={iconSize} icon={icon} position={popupPosition} {...popupProps}/>
</span>
</div>
}

View file

@ -244,17 +244,37 @@ function VideoFileNameForm({form}) {
}
}
const label = <InfoHeader
headerSize='h5'
headerContent='Video File Format'
popupProps={{wide: 'very', position: 'top left'}}
popupContent={<>
<p>Common yt-dlp variables:</p>
<ul>
<li><code>%(title)s</code> - Video title</li>
<li><code>%(uploader)s</code> - Channel/uploader name</li>
<li><code>%(upload_date)s</code> - Upload date (YYYYMMDD)</li>
<li><code>%(id)s</code> - Video ID</li>
<li><code>%(ext)s</code> - File extension</li>
<li><code>%(channel)s</code> - Channel name</li>
<li><code>%(duration)s</code> - Duration in seconds</li>
<li><code>%(playlist_index)s</code> - Playlist index</li>
</ul>
<p>See yt-dlp docs for all variables. Subdirectories supported.</p>
</>}
/>;
return <InputForm
form={form}
name='file_name_format'
path='yt_dlp_options.file_name_format'
label='Video File Format'
label={label}
onChange={onChange}
message={message}
/>
}
function VideosSettings() {
function VideosSettingsPage() {
useTitle('Videos Settings');
const emptyFormData = {
@ -301,7 +321,7 @@ function VideosSettings() {
if (_.isEmpty(tempProfiles)) {
tempProfiles = emptyProfilesOptions;
}
console.debug('VideosSettings: Got browser profiles:', tempProfiles);
console.debug('VideosSettingsPage: Got browser profiles:', tempProfiles);
setBrowserProfilesOptions(tempProfiles);
};
@ -523,7 +543,7 @@ export function VideosRoute(props) {
<Routes>
<Route path='/' exact element={<VideosPage/>}/>
<Route path='channel' exact element={<ChannelsPage/>}/>
<Route path='settings' exact element={<VideosSettings/>}/>
<Route path='settings' exact element={<VideosSettingsPage/>}/>
<Route path='statistics' exact element={<VideosStatistics/>}/>
<Route path='channel/new' exact element={<ChannelNewPage/>}/>
<Route path='channel/:channelId/edit' exact element={<ChannelEditPage/>}/>