Configs are displayed in new ConfigsPage under Admin.

- Configs can be imported and saved.
- Configs are validated before imported.
- API will refuse to save a config if it was not imported successfully.
This commit is contained in:
Roland 2024-09-28 17:28:33 -06:00
parent d34301a085
commit acf3dee179
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
22 changed files with 767 additions and 157 deletions

View file

@ -7,6 +7,7 @@ import {
getArchive,
getChannel,
getChannels,
getConfigs,
getDirectories,
getDownloads,
getFiles,
@ -17,7 +18,10 @@ import {
getStatus,
getVideo,
getVideosStatistics,
searchArchives, searchChannels,
postImportConfig,
postSaveConfig,
searchArchives,
searchChannels,
searchDirectories,
searchVideos,
searchZim,
@ -679,6 +683,44 @@ export const useDownloads = () => {
return {onceDownloads, recurringDownloads, pendingOnceDownloads, fetchDownloads}
}
export const useConfigs = () => {
const [configs, setConfigs] = useState(null);
const [loading, setLoading] = useState(false);
const fetchConfigs = async () => {
setLoading(true);
console.log('fetching configs...');
try {
const data = await getConfigs();
setConfigs(data['configs']);
console.debug('fetching configs successful');
} catch (e) {
console.error(e);
setConfigs(undefined);
} finally {
setLoading(false);
}
}
const importConfig = async (fileName) => {
try {
await postImportConfig(fileName);
} catch (e) {
console.error(e);
}
}
const saveConfig = async (fileName) => {
try {
await postSaveConfig(fileName);
} catch (e) {
console.error(e);
}
}
return {configs, loading, fetchConfigs, importConfig, saveConfig}
}
export const useThrottle = () => {
const [on, setOn] = useState(null);
const {settings, fetchSettings} = React.useContext(SettingsContext);