Moving config api endpoints to their own file..

This commit is contained in:
Roland 2024-12-03 22:30:12 -07:00
parent fc084e2421
commit 376850ceeb
No known key found for this signature in database
GPG key ID: 1BA620CE6C9A4680
10 changed files with 190 additions and 139 deletions

View file

@ -327,7 +327,7 @@ export async function getDownloads() {
}
export async function getConfigs() {
const response = await apiGet(`${API_URI}/configs`);
const response = await apiGet(`${API_URI}/config`);
if (response.ok) {
const data = await response.json();
return {
@ -347,7 +347,7 @@ export async function getConfigs() {
export async function postImportConfig(fileName) {
const body = {file_name: fileName};
const response = await apiPost(`${API_URI}/configs/import`, body);
const response = await apiPost(`${API_URI}/config/import`, body);
if (!response.ok) {
const message = await getErrorMessage(response, 'Could not import config.');
toast({
@ -360,14 +360,14 @@ export async function postImportConfig(fileName) {
return response
}
export async function postSaveConfig(fileName) {
export async function postDumpConfig(fileName) {
const body = {file_name: fileName, overwrite: true};
const response = await apiPost(`${API_URI}/configs/save`, body);
const response = await apiPost(`${API_URI}/config/dump`, body);
if (!response.ok) {
const message = await getErrorMessage(response, 'Could not save config.');
const message = await getErrorMessage(response, 'Could not dump config.');
toast({
type: 'error',
title: 'Saving config Failed',
title: 'Dumping config failed',
description: message,
time: 5000,
});
@ -375,19 +375,27 @@ export async function postSaveConfig(fileName) {
return response
}
export async function fetchVideoDownloaderConfig() {
const response = await apiGet(`${API_URI}/config/videos_downloader.yaml`);
export async function getConfig(fileName) {
const response = await apiGet(`${API_URI}/config?file_name=${fileName}`);
return (await response.json())['config'];
}
export async function saveVideoDownloaderConfig(config) {
export async function fetchVideoDownloaderConfig() {
return await getConfig('videos_downloader.yaml');
}
export async function updateConfig(fileName, config) {
const body = {config};
const response = await apiPost(`${API_URI}/config/videos_downloader.yaml`, body);
const response = await apiPost(`${API_URI}/config?file_name=${fileName}`, body);
if (!response.ok) {
throw Error('Failed to save config');
}
}
export async function updateVideoDownloaderConfig(config) {
return await updateConfig('videos_downloader.yaml', config);
}
export async function validateRegex(regex) {
const response = await apiPost(`${API_URI}/valid_regex`, {regex});
try {

View file

@ -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, postVideoFileFormat, saveVideoDownloaderConfig} from "../api";
import {deleteVideos, fetchVideoDownloaderConfig, postVideoFileFormat, updateVideoDownloaderConfig} from "../api";
import {Media, QueryContext, ThemeContext} from "../contexts/contexts";
import _ from "lodash";
import {defaultFileOrder, defaultSearchOrder} from "./Vars";
@ -264,7 +264,7 @@ function VideosSettings() {
}
const submitter = async () => {
return await saveVideoDownloaderConfig(form.formData);
return await updateVideoDownloaderConfig(form.formData);
}
const form = useForm({

View file

@ -19,7 +19,7 @@ import {
getVideo,
getVideosStatistics,
postImportConfig,
postSaveConfig,
postDumpConfig,
saveSettings,
searchArchives,
searchChannels,
@ -722,7 +722,7 @@ export const useConfigs = () => {
const saveConfig = async (fileName) => {
try {
await postSaveConfig(fileName);
await postDumpConfig(fileName);
} catch (e) {
console.error(e);
}