refac appsettings page

This commit is contained in:
Simon 2025-01-09 22:16:39 +07:00
parent 1a6f51a122
commit f6b5de00df
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
5 changed files with 492 additions and 801 deletions

View File

@ -1,37 +1,12 @@
import APIClient from '../../functions/APIClient'; import APIClient from '../../functions/APIClient';
import { AppSettingsConfigType } from '../loader/loadAppsettingsConfig';
type ObjectType = Record< const updateAppsettingsConfig = async (
string, configKey: string,
string | number | boolean | Record<string, string | number | boolean> configValue: string | boolean | number | null,
>; ) => {
function flattenObject(ob: ObjectType) {
// source: https://stackoverflow.com/a/53739792
const toReturn: ObjectType = {};
for (const i in ob) {
if (!Object.prototype.hasOwnProperty.call(ob, i)) continue;
if (typeof ob[i] == 'object' && ob[i] !== null) {
const flatObject = flattenObject(ob[i]);
for (const x in flatObject) {
if (!Object.prototype.hasOwnProperty.call(flatObject, x)) continue;
toReturn[i + '.' + x] = flatObject[x];
}
} else {
toReturn[i] = ob[i];
}
}
return toReturn;
}
const updateAppsettingsConfig = async (config: AppSettingsConfigType) => {
return APIClient('/api/appsettings/config/', { return APIClient('/api/appsettings/config/', {
method: 'POST', method: 'POST',
body: flattenObject(config), body: { [configKey]: configValue },
}); });
}; };

View File

@ -8,21 +8,21 @@ export type AppSettingsConfigType = {
auto_start: boolean; auto_start: boolean;
}; };
downloads: { downloads: {
limit_speed: false | number; limit_speed: number | undefined;
sleep_interval: number; sleep_interval: number;
autodelete_days: number; autodelete_days: number;
format: number | string; format: string | undefined;
format_sort: boolean | string; format_sort: string | undefined;
add_metadata: boolean; add_metadata: boolean;
add_thumbnail: boolean; add_thumbnail: boolean;
subtitle: boolean | string; subtitle: string | undefined;
subtitle_source: boolean | string; subtitle_source: boolean | string;
subtitle_index: boolean; subtitle_index: boolean;
comment_max: string | number; comment_max: string | undefined;
comment_sort: string; comment_sort: string;
cookie_import: boolean; cookie_import: boolean;
throttledratelimit: false | number; throttledratelimit: number | undefined;
extractor_lang: boolean | string; extractor_lang: string | undefined;
integrate_ryd: boolean; integrate_ryd: boolean;
integrate_sponsorblock: boolean; integrate_sponsorblock: boolean;
}; };

View File

@ -6,7 +6,7 @@ type InputTextProps = {
| React.Dispatch<React.SetStateAction<string | null>> | React.Dispatch<React.SetStateAction<string | null>>
| React.Dispatch<React.SetStateAction<number | null>>; | React.Dispatch<React.SetStateAction<number | null>>;
oldValue: string | number | undefined; oldValue: string | number | undefined;
updateCallback: (arg0: string, arg1: string | number | null) => void; updateCallback: (arg0: string, arg1: string | boolean | number | null) => void;
}; };
const InputConfig = ({ type, name, value, setValue, oldValue, updateCallback }: InputTextProps) => { const InputConfig = ({ type, name, value, setValue, oldValue, updateCallback }: InputTextProps) => {

File diff suppressed because it is too large Load Diff

View File

@ -108,6 +108,10 @@ input {
border: solid 1px var(--main-font); border: solid 1px var(--main-font);
} }
input[readonly] {
background-color: var(--main-font);
}
textarea { textarea {
width: 100%; width: 100%;
} }