fix: use sanitized PDF options from validator in convert/demo routes (BUG-102)
All checks were successful
Build & Deploy to Staging / Build & Deploy to Staging (push) Successful in 12m44s

This commit is contained in:
OpenClaw 2026-03-05 08:05:22 +01:00
parent c03f217690
commit ba2e542e2a
3 changed files with 117 additions and 45 deletions

View file

@ -127,11 +127,15 @@ router.post("/html", async (req: Request & { acquirePdfSlot?: () => Promise<void
? injectWatermark(body.html)
: injectWatermark(wrapHtml(body.html, body.css));
const defaultOpts = {
format: "A4",
landscape: false,
printBackground: true,
margin: { top: "0", right: "0", bottom: "0", left: "0" },
};
const pdf = await renderPdf(fullHtml, {
format: body.format || "A4",
landscape: body.landscape || false,
printBackground: body.printBackground !== false,
margin: body.margin || { top: "0", right: "0", bottom: "0", left: "0" },
...defaultOpts,
...validation.sanitized,
});
const filename = sanitizeFilename(body.filename || "demo.pdf");
@ -227,11 +231,15 @@ router.post("/markdown", async (req: Request & { acquirePdfSlot?: () => Promise<
const htmlContent = markdownToHtml(body.markdown);
const fullHtml = injectWatermark(wrapHtml(htmlContent, body.css));
const defaultOpts = {
format: "A4",
landscape: false,
printBackground: true,
margin: { top: "0", right: "0", bottom: "0", left: "0" },
};
const pdf = await renderPdf(fullHtml, {
format: body.format || "A4",
landscape: body.landscape || false,
printBackground: body.printBackground !== false,
margin: body.margin || { top: "0", right: "0", bottom: "0", left: "0" },
...defaultOpts,
...validation.sanitized,
});
const filename = sanitizeFilename(body.filename || "demo.pdf");