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)
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user