mirror of
https://git.vectorsigma.ru/public/tubearchivist.git
synced 2026-08-08 07:50:07 +00:00
refac appsettings page
This commit is contained in:
@@ -1,37 +1,12 @@
|
||||
import APIClient from '../../functions/APIClient';
|
||||
import { AppSettingsConfigType } from '../loader/loadAppsettingsConfig';
|
||||
|
||||
type ObjectType = Record<
|
||||
string,
|
||||
string | number | boolean | Record<string, string | number | boolean>
|
||||
>;
|
||||
|
||||
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) => {
|
||||
const updateAppsettingsConfig = async (
|
||||
configKey: string,
|
||||
configValue: string | boolean | number | null,
|
||||
) => {
|
||||
return APIClient('/api/appsettings/config/', {
|
||||
method: 'POST',
|
||||
body: flattenObject(config),
|
||||
body: { [configKey]: configValue },
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user