fixes tag delete

This commit is contained in:
Christian Beutel
2025-10-05 13:15:19 +02:00
parent 237225f10b
commit 81d148c09f
+47 -8
View File
@@ -7,7 +7,7 @@ export function getFileURL(record: { [key: string]: any; }, filename?: string, t
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) {
@@ -50,16 +50,55 @@ export function saveAs(data: Blob, fileName: string) {
window.URL.revokeObjectURL(url);
};
function buildFormData(formData: FormData, data: any, parentKey?: string, exclude?: string[]) {
if (data && typeof data === 'object' && !(data instanceof Date) && !(data instanceof File) && !(data instanceof Blob)) {
Object.keys(data).forEach(key => {
if (exclude?.includes(key)) {
function buildFormData(
formData: FormData,
data: any,
parentKey?: string,
exclude: string[] = []
) {
if (data === null || data === undefined) {
return;
}
// 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);
});
}
// 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;
}
buildFormData(formData, data[key], parentKey ? `${parentKey}` : key);
const value = data[key];
const newKey = parentKey ? `${parentKey}.${key}` : key;
buildFormData(formData, value, newKey, exclude);
});
} else {
const value = data == null ? '' : data;
}
// Handle primitives and special types
else {
const value =
data instanceof Date
? data.toISOString()
: data == null
? ''
: data;
formData.append(parentKey!, value);
}