mirror of
https://github.com/projectdysnomia/dysnomia.git
synced 2026-12-02 13:48:31 +02:00
33 lines
763 B
JavaScript
33 lines
763 B
JavaScript
function processAttachments(attachments) {
|
|
if(!attachments) {
|
|
return {};
|
|
}
|
|
const files = [];
|
|
const resultAttachments = [];
|
|
|
|
attachments.forEach((attachment, idx) => {
|
|
if(attachment.id) {
|
|
resultAttachments.push(attachment);
|
|
} else {
|
|
files.push({
|
|
fieldName: `files[${idx}]`,
|
|
file: attachment.file,
|
|
name: attachment.filename
|
|
});
|
|
|
|
resultAttachments.push({
|
|
...attachment,
|
|
file: undefined,
|
|
id: idx
|
|
});
|
|
}
|
|
});
|
|
|
|
return {
|
|
files: files.length ? files : undefined,
|
|
attachments: resultAttachments
|
|
};
|
|
}
|
|
|
|
module.exports = processAttachments;
|