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

@@ -77,9 +77,23 @@ export default function add(pool) {
if (rawContent == null) {
throw new Error('Content required');
}
const content = Buffer.isBuffer(rawContent)
? rawContent
: Buffer.from(rawContent);
let content;
if (Buffer.isBuffer(rawContent)) {
content = rawContent;
} else if (typeof rawContent === 'string') {
const trimmed = rawContent.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(rawContent, 'utf8');
}
} else {
content = Buffer.from(rawContent, 'utf8');
}
} else {
content = Buffer.from(rawContent);
}
if (rawSort !== undefined && rawSort !== null) {
if (!Number.isFinite(rawSort)) {
@@ -143,7 +157,7 @@ export default function add(pool) {
}
if (!thumbavif) {
const generated = await generateDocumentThumb(content, mimetype);
const generated = await generateDocumentThumb(content, mimetype, { filename: rawName });
thumbavif = generated.thumbavif;
thumbx = generated.thumbx;
thumby = generated.thumby;