ragflow/web/src/utils/commonUtil.ts
balibabu 6405041b4d
fix: cannot save the system model setting #468 (#508)
### What problem does this PR solve?

fix: cannot save the system model setting #468
feat: rename file in FileManager
feat: add FileManager
feat: override useSelector type

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
2024-04-23 17:46:56 +08:00

30 lines
845 B
TypeScript

import isObject from 'lodash/isObject';
import snakeCase from 'lodash/snakeCase';
export const isFormData = (data: unknown): data is FormData => {
return data instanceof FormData;
};
const excludedFields = ['img2txt_id'];
const isExcludedField = (key: string) => {
return excludedFields.includes(key);
};
export const convertTheKeysOfTheObjectToSnake = (data: unknown) => {
if (isObject(data) && !isFormData(data)) {
return Object.keys(data).reduce<Record<string, any>>((pre, cur) => {
const value = (data as Record<string, any>)[cur];
pre[isFormData(value) || isExcludedField(cur) ? cur : snakeCase(cur)] =
value;
return pre;
}, {});
}
return data;
};
export const getSearchValue = (key: string) => {
const params = new URL(document.location as any).searchParams;
return params.get(key);
};