fllabcks hmmm
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user