u
This commit is contained in:
@@ -61,6 +61,7 @@ function parseDeliveryPayload(req) {
|
||||
const name = f.originalname || '';
|
||||
const isPdf = f.mimetype === 'application/pdf' || name.toLowerCase().endsWith('.pdf');
|
||||
const mimetype = isPdf ? 'application/pdf' : 'text/plain';
|
||||
console.log(`[delivery upload] Received multipart file "${name}": ${f.size} bytes, mimetype=${mimetype}`);
|
||||
return {
|
||||
mimetype,
|
||||
name: f.originalname,
|
||||
@@ -69,6 +70,29 @@ function parseDeliveryPayload(req) {
|
||||
meta: metaObj.meta ?? null,
|
||||
};
|
||||
});
|
||||
} else if (Array.isArray(files) && files.length > 0) {
|
||||
files = files.map((f) => {
|
||||
let content = f.content;
|
||||
if (typeof content === 'string') {
|
||||
const trimmed = content.trim();
|
||||
if (f.mimetype === 'application/pdf' || trimmed.startsWith('JVBER') || /^[A-Za-z0-9+/=]+$/.test(trimmed.slice(0, 100))) {
|
||||
try {
|
||||
content = Buffer.from(trimmed, 'base64');
|
||||
} catch {
|
||||
content = Buffer.from(content, 'utf8');
|
||||
}
|
||||
} else {
|
||||
content = Buffer.from(content, 'utf8');
|
||||
}
|
||||
}
|
||||
const size = Buffer.isBuffer(content) ? content.length : (f.size ?? 0);
|
||||
console.log(`[delivery upload] Received JSON file "${f.name}": ${size} bytes, mimetype=${f.mimetype}`);
|
||||
return {
|
||||
...f,
|
||||
content,
|
||||
size,
|
||||
};
|
||||
});
|
||||
}
|
||||
return { payload, externalNumber, date, supplierId, lines, files };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user