From 05835cbd48966601144c14238319cfb3685e3f2e Mon Sep 17 00:00:00 2001 From: sauravniraula Date: Sun, 20 Jul 2025 23:33:10 +0545 Subject: [PATCH 1/2] chore(nextjs): pdf export puppeteer config --- servers/nextjs/app/api/export-as-pdf/route.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/servers/nextjs/app/api/export-as-pdf/route.ts b/servers/nextjs/app/api/export-as-pdf/route.ts index 77798b8e..8a60e10e 100644 --- a/servers/nextjs/app/api/export-as-pdf/route.ts +++ b/servers/nextjs/app/api/export-as-pdf/route.ts @@ -7,17 +7,25 @@ import { NextResponse, NextRequest } from 'next/server'; export async function POST(req: NextRequest) { - const { id, title } = await req.json(); + const { id, title } = await req.json(); console.log('path', process.env.APP_DATA_DIRECTORY); if (!id) { return NextResponse.json({ error: "Missing Presentation ID" }, { status: 400 }); } const browser = await puppeteer.launch({ headless: true, - args: ['--no-sandbox', '--disable-setuid-sandbox'] + args: [ + '--no-sandbox', + '--disable-setuid-sandbox', + '--disable-dev-shm-usage', + '--disable-gpu', + '--disable-web-security', + '--window-size=1920,1080' + ] }); const page = await browser.newPage(); - await page.goto(`http://localhost/pdf-maker?id=${id}`, { waitUntil: 'networkidle0' }); + await page.goto(`http://localhost/pdf-maker?id=${id}`); + await page.waitForNetworkIdle(); const pdfBuffer = await page.pdf({ printBackground: true, @@ -27,7 +35,7 @@ export async function POST(req: NextRequest) { }); browser.close(); const sanitizedTitle = sanitizeFilename(title); - const destinationPath = path.join(process.env.APP_DATA_DIRECTORY!,'exports', `${sanitizedTitle}.pdf`); + const destinationPath = path.join(process.env.APP_DATA_DIRECTORY!, 'exports', `${sanitizedTitle}.pdf`); console.log('destinationPath', destinationPath); await fs.promises.writeFile(destinationPath, pdfBuffer); From aaaf16543fe746bf1e483767fb402d86f08e38fc Mon Sep 17 00:00:00 2001 From: sauravniraula Date: Mon, 21 Jul 2025 00:36:24 +0545 Subject: [PATCH 2/2] perf(nextjs): evaluates slide element attributes in parallel --- .../nextjs/app/api/presentation_to_pptx_model/route.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/servers/nextjs/app/api/presentation_to_pptx_model/route.ts b/servers/nextjs/app/api/presentation_to_pptx_model/route.ts index f5eceb0c..c39a9c79 100644 --- a/servers/nextjs/app/api/presentation_to_pptx_model/route.ts +++ b/servers/nextjs/app/api/presentation_to_pptx_model/route.ts @@ -159,11 +159,9 @@ async function screenshotElement(element: ElementAttributes, screenshotsDir: str async function getSlidesAttributes(slides: ElementHandle[], screenshotsDir: string): Promise { - const slideAttributes = []; - for (const slide of slides) { - const attributes = await getAllChildElementsAttributes({ element: slide, screenshotsDir }); - slideAttributes.push(attributes); - } + const slideAttributes = await Promise.all( + slides.map((slide) => getAllChildElementsAttributes({ element: slide, screenshotsDir })) + ); return slideAttributes; }