forked from refinedev/refine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
normalize.ts
50 lines (46 loc) · 1.42 KB
/
normalize.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
export const getValueProps = (data: any, imageUrl: string) => {
if (!data) {
return { fileList: [] };
}
return {
file: data.file,
fileList:
data.fileList ??
(Array.isArray(data) ? data : [...data]).map((item: any) => {
const file: any = {
name: item.name,
percent: item.percent,
size: item.size,
status: item.status,
type: item.mime || item.type,
uid: item.id,
};
if (item.url) {
file.url = `${imageUrl}${item.url}`;
}
return file;
}),
};
};
export const mediaUploadMapper = (params: any) => {
Object.keys(params).map((item) => {
if (params[item]) {
const param = params[item].fileList;
const isMediaField = Array.isArray(param);
if (isMediaField) {
const ids = [];
for (const item of param) {
if (item.response) {
for (const response of item.response) {
ids.push(response.id);
}
} else {
ids.push(item.uid);
}
}
params[item] = ids;
}
}
});
return params;
};