From 96d35bcf6d3a2575e76c1128219ad6b4e59b4423 Mon Sep 17 00:00:00 2001 From: seb Date: Sat, 19 Sep 2026 05:14:41 +0200 Subject: [PATCH] u --- src/api/routes/delivery.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/api/routes/delivery.js b/src/api/routes/delivery.js index 073dbb6..c26808a 100644 --- a/src/api/routes/delivery.js +++ b/src/api/routes/delivery.js @@ -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 }; }