mirror of
https://github.com/versia-pub/server.git
synced 2026-04-28 05:09:16 +02:00
refactor(api): ♻️ Reduce complexity of a few functions
This commit is contained in:
parent
25ea870f71
commit
411fcd8af5
2 changed files with 72 additions and 81 deletions
|
|
@ -45,20 +45,17 @@ const objectToFormData = (
|
|||
} else if (Array.isArray(value)) {
|
||||
for (const [index, item] of value.entries()) {
|
||||
const arrayKey = `${fullKey}[${index}]`;
|
||||
|
||||
if (item instanceof File) {
|
||||
formData.append(arrayKey, item as Blob);
|
||||
formData.append(arrayKey, item);
|
||||
} else if (typeof item === "object") {
|
||||
objectToFormData(
|
||||
item as ConvertibleObject,
|
||||
formData,
|
||||
arrayKey,
|
||||
);
|
||||
objectToFormData(item, formData, arrayKey);
|
||||
} else {
|
||||
formData.append(arrayKey, String(item));
|
||||
}
|
||||
}
|
||||
} else if (typeof value === "object") {
|
||||
objectToFormData(value as ConvertibleObject, formData, fullKey);
|
||||
objectToFormData(value, formData, fullKey);
|
||||
} else {
|
||||
formData.append(fullKey, String(value));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue