fllabcks hmmm

This commit is contained in:
seb
2026-09-18 08:28:44 +02:00
parent bac6f2a801
commit b69110f1c2
3 changed files with 276 additions and 38 deletions

View File

@@ -60,9 +60,23 @@ function normalizeAttachment(raw, index) {
if (raw.content == null) {
throw new Error('Invalid file');
}
const content = Buffer.isBuffer(raw.content)
? raw.content
: Buffer.from(raw.content);
let content;
if (Buffer.isBuffer(raw.content)) {
content = raw.content;
} else if (typeof raw.content === 'string') {
const trimmed = raw.content.trim();
if (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(raw.content, 'utf8');
}
} else {
content = Buffer.from(raw.content, 'utf8');
}
} else {
content = Buffer.from(raw.content);
}
const size = Number.isFinite(raw.size) && raw.size >= 0
? Number(raw.size)
@@ -137,7 +151,7 @@ export async function insertAttachments(pool, tx, sql, manifestId, files) {
nextSort = Math.max(nextSort, sort) + 1;
// Generate thumbnail server-side (e.g. pdftocairo + sharp for PDF)
const { thumbavif, thumbx, thumby } = await generateDocumentThumb(a.content, a.mimetype);
const { thumbavif, thumbx, thumby } = await generateDocumentThumb(a.content, a.mimetype, { filename: a.name });
const fileRes = await request(pool, tx)
.input('hash', a.hash)