mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-21 15:36:18 -05:00
Adding download window which can prevent downloads from running at unwanted times.
This commit is contained in:
parent
4579562be5
commit
35994bd363
10 changed files with 395 additions and 57 deletions
122
app/cypress/e2e/settings/download-window.cy.js
Normal file
122
app/cypress/e2e/settings/download-window.cy.js
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
describe('Download Window Settings', () => {
|
||||
const mockSettings = {
|
||||
archive_destination: 'archive/%(domain_tag)s/%(domain)s',
|
||||
download_manager_disabled: false,
|
||||
download_manager_stopped: false,
|
||||
download_on_startup: true,
|
||||
download_timeout: 0,
|
||||
download_wait: 20,
|
||||
download_window_start: null,
|
||||
download_window_end: null,
|
||||
hotspot_device: 'wlan0',
|
||||
hotspot_on_startup: true,
|
||||
hotspot_password: 'wrolpi hotspot',
|
||||
hotspot_ssid: 'WROLPi',
|
||||
check_for_upgrades: true,
|
||||
ignore_outdated_zims: false,
|
||||
log_level: 'info',
|
||||
map_destination: 'map',
|
||||
nav_color: 'violet',
|
||||
media_directory: '/media/wrolpi',
|
||||
tags_directory: true,
|
||||
throttle_on_startup: false,
|
||||
version: '1.0.0',
|
||||
videos_destination: 'videos/%(channel_tag)s/%(channel_name)s',
|
||||
wrol_mode: false,
|
||||
zims_destination: 'zims',
|
||||
save_ffprobe_json: true,
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
cy.intercept('GET', '/api/status', {
|
||||
statusCode: 200,
|
||||
body: {
|
||||
version: '1.0.0',
|
||||
flags: {},
|
||||
cpu_percent: 10,
|
||||
memory_percent: 30,
|
||||
downloads: {pending: 0, recurring: 0, disabled: false, stopped: false, outside_download_window: false},
|
||||
}
|
||||
}).as('getStatus');
|
||||
|
||||
cy.intercept('GET', '/api/tags', {
|
||||
statusCode: 200,
|
||||
body: {tags: []}
|
||||
}).as('getTags');
|
||||
|
||||
cy.intercept('GET', '/api/events', {
|
||||
statusCode: 200,
|
||||
body: {events: []}
|
||||
}).as('getEvents');
|
||||
|
||||
cy.intercept('POST', '/api/search/suggestions', {
|
||||
statusCode: 200,
|
||||
body: {fileGroups: 0, zimsEstimates: [], channels: [], domains: []}
|
||||
}).as('getSuggestions');
|
||||
});
|
||||
|
||||
it('time inputs are empty when no window is configured', () => {
|
||||
cy.intercept('GET', '/api/settings', {
|
||||
statusCode: 200,
|
||||
body: {...mockSettings},
|
||||
}).as('getSettings');
|
||||
|
||||
cy.visit('/admin/settings');
|
||||
cy.wait('@getSettings');
|
||||
|
||||
cy.get('input[type="time"]').should('have.length', 2);
|
||||
cy.get('input[type="time"]').first().should('have.value', '');
|
||||
cy.get('input[type="time"]').last().should('have.value', '');
|
||||
});
|
||||
|
||||
it('displays saved download window values from API', () => {
|
||||
cy.intercept('GET', '/api/settings', {
|
||||
statusCode: 200,
|
||||
body: {
|
||||
...mockSettings,
|
||||
download_window_start: '08:00',
|
||||
download_window_end: '17:00',
|
||||
},
|
||||
}).as('getSettings');
|
||||
|
||||
cy.visit('/admin/settings');
|
||||
cy.wait('@getSettings');
|
||||
|
||||
cy.get('input[type="time"]').should('have.length', 2);
|
||||
cy.get('input[type="time"]').first().should('have.value', '08:00');
|
||||
cy.get('input[type="time"]').last().should('have.value', '17:00');
|
||||
});
|
||||
|
||||
it('can set download window values', () => {
|
||||
cy.intercept('GET', '/api/settings', {
|
||||
statusCode: 200,
|
||||
body: {...mockSettings},
|
||||
}).as('getSettings');
|
||||
|
||||
cy.visit('/admin/settings');
|
||||
cy.wait('@getSettings');
|
||||
|
||||
cy.get('input[type="time"]').first().type('08:00');
|
||||
cy.get('input[type="time"]').first().should('have.value', '08:00');
|
||||
|
||||
cy.get('input[type="time"]').last().type('17:00');
|
||||
cy.get('input[type="time"]').last().should('have.value', '17:00');
|
||||
});
|
||||
|
||||
it('displays overnight window values from API', () => {
|
||||
cy.intercept('GET', '/api/settings', {
|
||||
statusCode: 200,
|
||||
body: {
|
||||
...mockSettings,
|
||||
download_window_start: '22:00',
|
||||
download_window_end: '06:00',
|
||||
},
|
||||
}).as('getSettings');
|
||||
|
||||
cy.visit('/admin/settings');
|
||||
cy.wait('@getSettings');
|
||||
|
||||
cy.get('input[type="time"]').first().should('have.value', '22:00');
|
||||
cy.get('input[type="time"]').last().should('have.value', '06:00');
|
||||
});
|
||||
});
|
||||
|
|
@ -302,6 +302,8 @@ export async function getSettings() {
|
|||
download_on_startup: content.download_on_startup,
|
||||
download_timeout: content.download_timeout,
|
||||
download_wait: content.download_wait,
|
||||
download_window_start: content.download_window_start,
|
||||
download_window_end: content.download_window_end,
|
||||
hotspot_device: content.hotspot_device,
|
||||
hotspot_on_startup: content.hotspot_on_startup,
|
||||
hotspot_password: content.hotspot_password,
|
||||
|
|
|
|||
|
|
@ -591,6 +591,17 @@ export function WROLModeMessage({content}) {
|
|||
return null;
|
||||
}
|
||||
|
||||
export function DownloadWindowMessage() {
|
||||
const {status} = React.useContext(StatusContext);
|
||||
const downloads = status ? status.downloads : null;
|
||||
|
||||
if (downloads && downloads.outside_download_window) {
|
||||
return <Message icon='clock outline' header='Outside Download Window'
|
||||
content='Downloads are paused because the current time is outside the configured download window.'/>
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export function CookiesUnlockModal({open, onClose, onSuccess}) {
|
||||
const [password, setPassword] = useState('');
|
||||
const [submitting, setSubmitting] = useState(false);
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ import {
|
|||
APIButton,
|
||||
CookiesLockedMessage,
|
||||
DisableDownloadsToggle,
|
||||
DownloadWindowMessage,
|
||||
ErrorMessage,
|
||||
formatFrequency,
|
||||
humanBandwidth,
|
||||
|
|
@ -681,6 +682,7 @@ export function DownloadsPage() {
|
|||
|
||||
return <>
|
||||
<WROLModeMessage content='Downloads are disabled because WROL Mode is enabled.'/>
|
||||
<DownloadWindowMessage/>
|
||||
<DisableDownloadsToggle/>
|
||||
<CookiesLockedMessage/>
|
||||
|
||||
|
|
|
|||
|
|
@ -443,6 +443,8 @@ export function SettingsPage() {
|
|||
download_on_startup: settings.download_on_startup,
|
||||
download_timeout: settings.download_timeout,
|
||||
download_wait: settings.download_wait,
|
||||
download_window_start: settings.download_window_start || '',
|
||||
download_window_end: settings.download_window_end || '',
|
||||
hotspot_device: settings.hotspot_device,
|
||||
hotspot_on_startup: settings.hotspot_on_startup,
|
||||
hotspot_password: settings.hotspot_password,
|
||||
|
|
@ -562,34 +564,46 @@ export function SettingsPage() {
|
|||
/>
|
||||
</div>
|
||||
|
||||
<Form.Group inline>
|
||||
<Form.Input
|
||||
label={<>
|
||||
<b>Wait Between Downloads</b>
|
||||
<InfoPopup
|
||||
content='Number of seconds to wait after each download completes. This helps download "nicely" by being polite to servers. Set to 0 to disable waiting.'/>
|
||||
</>}
|
||||
value={state.download_wait}
|
||||
disabled={disabled || state.download_wait === null}
|
||||
onChange={(e, i) => handleTimeoutChange(e, 'download_wait', i.value)}
|
||||
/>
|
||||
</Form.Group>
|
||||
<br/>
|
||||
|
||||
<Form.Group inline>
|
||||
<Form.Input
|
||||
label={<>
|
||||
<b>Download Timeout</b>
|
||||
<InfoPopup content='Downloads will be stopped after this many seconds have elapsed.
|
||||
Downloads will never timeout if this is empty.'/>
|
||||
</>}
|
||||
value={state.download_timeout}
|
||||
disabled={disabled || state.download_timeout === null}
|
||||
onChange={(e, i) => handleTimeoutChange(e, 'download_timeout', i.value)}
|
||||
<label htmlFor='log_levels_input'>Log Level: {logLevelToName(state.log_level)}</label>
|
||||
<br/>
|
||||
<input type='range'
|
||||
id='log_levels_input'
|
||||
list='log_levels'
|
||||
min='1'
|
||||
max='5'
|
||||
value={state.log_level}
|
||||
onChange={e => setState({...state, log_level: parseInt(e.target.value)})}
|
||||
style={{marginBottom: '1em'}}
|
||||
/>
|
||||
<datalist id='log_levels'>
|
||||
<option value='1'>Critical</option>
|
||||
<option value='2'>Warning</option>
|
||||
<option value='3'>Info</option>
|
||||
<option value='4'>Debug</option>
|
||||
<option value='5'>Trace</option>
|
||||
</datalist>
|
||||
|
||||
<br/>
|
||||
|
||||
<ButtonGroup>
|
||||
<Button color={state.nav_color} onClick={e => e.preventDefault()}>Navbar Color</Button>
|
||||
<Dropdown
|
||||
id='settings_navbar_color_dropdown'
|
||||
className='button icon'
|
||||
floating
|
||||
options={navColorOptions}
|
||||
onChange={(e, {value}) => setState({...state, nav_color: value})}
|
||||
value={state.nav_color}
|
||||
/>
|
||||
</Form.Group>
|
||||
</ButtonGroup>
|
||||
|
||||
</Grid.Column>
|
||||
<Grid.Column>
|
||||
<Segment>
|
||||
<Header as='h3'>Hotspot Settings</Header>
|
||||
|
||||
<Form.Input
|
||||
label='Hotspot SSID'
|
||||
value={state.hotspot_ssid}
|
||||
|
|
@ -638,40 +652,61 @@ export function SettingsPage() {
|
|||
</Grid>
|
||||
|
||||
|
||||
<br/>
|
||||
<Divider/>
|
||||
<Header as='h3'>Download settings</Header>
|
||||
|
||||
<label htmlFor='log_levels_input'>Log Level: {logLevelToName(state.log_level)}</label>
|
||||
<br/>
|
||||
<input type='range'
|
||||
id='log_levels_input'
|
||||
list='log_levels'
|
||||
min='1'
|
||||
max='5'
|
||||
value={state.log_level}
|
||||
onChange={e => setState({...state, log_level: parseInt(e.target.value)})}
|
||||
style={{marginBottom: '1em'}}
|
||||
/>
|
||||
<datalist id='log_levels'>
|
||||
<option value='1'>Critical</option>
|
||||
<option value='2'>Warning</option>
|
||||
<option value='3'>Info</option>
|
||||
<option value='4'>Debug</option>
|
||||
<option value='5'>Trace</option>
|
||||
</datalist>
|
||||
|
||||
<br/>
|
||||
|
||||
<ButtonGroup>
|
||||
<Button color={state.nav_color} onClick={e => e.preventDefault()}>Navbar Color</Button>
|
||||
<Dropdown
|
||||
id='settings_navbar_color_dropdown'
|
||||
className='button icon'
|
||||
floating
|
||||
options={navColorOptions}
|
||||
onChange={(e, {value}) => setState({...state, nav_color: value})}
|
||||
value={state.nav_color}
|
||||
<Form.Group inline>
|
||||
<Form.Input
|
||||
label={<>
|
||||
<b>Wait Between Downloads</b>
|
||||
<InfoPopup
|
||||
content='Number of seconds to wait after each download completes. This helps download "nicely" by being polite to servers. Set to 0 to disable waiting.'/>
|
||||
</>}
|
||||
value={state.download_wait}
|
||||
disabled={disabled || state.download_wait === null}
|
||||
onChange={(e, i) => handleTimeoutChange(e, 'download_wait', i.value)}
|
||||
/>
|
||||
</ButtonGroup>
|
||||
</Form.Group>
|
||||
<Form.Group inline>
|
||||
<Form.Input
|
||||
label={<>
|
||||
<b>Download Timeout</b>
|
||||
<InfoPopup content='Downloads will be stopped after this many seconds have elapsed.
|
||||
Downloads will never timeout if this is empty.'/>
|
||||
</>}
|
||||
value={state.download_timeout}
|
||||
disabled={disabled || state.download_timeout === null}
|
||||
onChange={(e, i) => handleTimeoutChange(e, 'download_timeout', i.value)}
|
||||
/>
|
||||
</Form.Group>
|
||||
|
||||
<Form.Group inline>
|
||||
<Form.Input
|
||||
label={<>
|
||||
<b>Download Window Start</b>
|
||||
<InfoPopup
|
||||
content='Start time for allowed download window (HH:MM, 24-hour). Leave both empty for no restriction.'/>
|
||||
</>}
|
||||
type='time'
|
||||
value={state.download_window_start}
|
||||
disabled={disabled}
|
||||
onChange={(e, i) => handleInputChange(e, 'download_window_start', i.value)}
|
||||
/>
|
||||
</Form.Group>
|
||||
|
||||
<Form.Group inline>
|
||||
<Form.Input
|
||||
label={<>
|
||||
<b>Download Window End</b>
|
||||
<InfoPopup
|
||||
content='End time for allowed download window (HH:MM, 24-hour). Leave both empty for no restriction.'/>
|
||||
</>}
|
||||
type='time'
|
||||
value={state.download_window_end}
|
||||
disabled={disabled}
|
||||
onChange={(e, i) => handleInputChange(e, 'download_window_end', i.value)}
|
||||
/>
|
||||
</Form.Group>
|
||||
|
||||
<Divider/>
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue