fixes tag delete
This commit is contained in:
@@ -7,7 +7,7 @@ export function getFileURL(record: { [key: string]: any; }, filename?: string, t
|
|||||||
return filename;
|
return filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
return `/api/v1/files/${record.collectionId}/${record.id}/${filename}${thumb ? '?thumb='+thumb : ''}`
|
return `/api/v1/files/${record.collectionId}/${record.id}/${filename}${thumb ? '?thumb=' + thumb : ''}`
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isURL(value: string) {
|
export function isURL(value: string) {
|
||||||
@@ -50,16 +50,55 @@ export function saveAs(data: Blob, fileName: string) {
|
|||||||
window.URL.revokeObjectURL(url);
|
window.URL.revokeObjectURL(url);
|
||||||
};
|
};
|
||||||
|
|
||||||
function buildFormData(formData: FormData, data: any, parentKey?: string, exclude?: string[]) {
|
function buildFormData(
|
||||||
if (data && typeof data === 'object' && !(data instanceof Date) && !(data instanceof File) && !(data instanceof Blob)) {
|
formData: FormData,
|
||||||
Object.keys(data).forEach(key => {
|
data: any,
|
||||||
if (exclude?.includes(key)) {
|
parentKey?: string,
|
||||||
|
exclude: string[] = []
|
||||||
|
) {
|
||||||
|
if (data === null || data === undefined) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
buildFormData(formData, data[key], parentKey ? `${parentKey}` : key);
|
|
||||||
|
// Handle arrays
|
||||||
|
if (Array.isArray(data)) {
|
||||||
|
if (data.length === 0) {
|
||||||
|
// Add an explicit empty entry for empty arrays
|
||||||
|
formData.append(parentKey!, '');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
data.forEach((value, index) => {
|
||||||
|
const key = parentKey ? `${parentKey}` : String(index);
|
||||||
|
buildFormData(formData, value, key, exclude);
|
||||||
});
|
});
|
||||||
} else {
|
}
|
||||||
const value = data == null ? '' : data;
|
|
||||||
|
// Handle objects (but not Date, File, Blob)
|
||||||
|
else if (
|
||||||
|
typeof data === 'object' &&
|
||||||
|
!(data instanceof Date) &&
|
||||||
|
!(data instanceof File) &&
|
||||||
|
!(data instanceof Blob)
|
||||||
|
) {
|
||||||
|
Object.keys(data).forEach((key) => {
|
||||||
|
if (exclude.includes(key)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const value = data[key];
|
||||||
|
const newKey = parentKey ? `${parentKey}.${key}` : key;
|
||||||
|
buildFormData(formData, value, newKey, exclude);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle primitives and special types
|
||||||
|
else {
|
||||||
|
const value =
|
||||||
|
data instanceof Date
|
||||||
|
? data.toISOString()
|
||||||
|
: data == null
|
||||||
|
? ''
|
||||||
|
: data;
|
||||||
|
|
||||||
formData.append(parentKey!, value);
|
formData.append(parentKey!, value);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user