feat: add PDF options validation to demo route (TDD)
All checks were successful
Build & Deploy to Staging / Build & Deploy to Staging (push) Successful in 14m58s
All checks were successful
Build & Deploy to Staging / Build & Deploy to Staging (push) Successful in 14m58s
This commit is contained in:
parent
a91b4c53a9
commit
ecc7b9640c
2 changed files with 68 additions and 4 deletions
|
|
@ -3,6 +3,8 @@ import rateLimit from "express-rate-limit";
|
|||
import { renderPdf } from "../services/browser.js";
|
||||
import { markdownToHtml, wrapHtml } from "../services/markdown.js";
|
||||
import logger from "../services/logger.js";
|
||||
import { sanitizeFilename } from "../utils/sanitize.js";
|
||||
import { validatePdfOptions } from "../utils/pdf-options.js";
|
||||
|
||||
const router = Router();
|
||||
|
||||
|
|
@ -42,10 +44,6 @@ interface DemoBody {
|
|||
filename?: string;
|
||||
}
|
||||
|
||||
function sanitizeFilename(name: string): string {
|
||||
return name.replace(/[\x00-\x1f"\\\r\n]/g, "").trim() || "document.pdf";
|
||||
}
|
||||
|
||||
/**
|
||||
* @openapi
|
||||
* /v1/demo/html:
|
||||
|
|
@ -114,6 +112,12 @@ router.post("/html", async (req: Request & { acquirePdfSlot?: () => Promise<void
|
|||
return;
|
||||
}
|
||||
|
||||
const validation = validatePdfOptions(body);
|
||||
if (!validation.valid) {
|
||||
res.status(400).json({ error: validation.error });
|
||||
return;
|
||||
}
|
||||
|
||||
if (req.acquirePdfSlot) {
|
||||
await req.acquirePdfSlot();
|
||||
slotAcquired = true;
|
||||
|
|
@ -209,6 +213,12 @@ router.post("/markdown", async (req: Request & { acquirePdfSlot?: () => Promise<
|
|||
return;
|
||||
}
|
||||
|
||||
const validation = validatePdfOptions(body);
|
||||
if (!validation.valid) {
|
||||
res.status(400).json({ error: validation.error });
|
||||
return;
|
||||
}
|
||||
|
||||
if (req.acquirePdfSlot) {
|
||||
await req.acquirePdfSlot();
|
||||
slotAcquired = true;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue