fix ppt download issue

This commit is contained in:
shubham.goyal@brandtech.plus 2026-05-17 20:07:56 +05:30
parent e63f790cd8
commit e054916f44
3 changed files with 27 additions and 8 deletions

View file

@ -17,6 +17,7 @@ import {
PopoverTrigger,
} from "@/components/ui/popover";
import { PresentationGenerationApi } from "../../services/api/presentation-generation";
import { apiFetch } from "@/lib/apiFetch";
import { OverlayLoader } from "@/components/ui/overlay-loader";
import { useDispatch, useSelector } from "react-redux";
@ -59,7 +60,7 @@ const Header = ({
const { onUndo, onRedo, canUndo, canRedo } = usePresentationUndoRedo();
const get_presentation_pptx_model = async (id: string): Promise<PptxPresentationModel> => {
const response = await fetch(`/api/presentation_to_pptx_model?id=${id}`);
const response = await apiFetch(`/api/presentation_to_pptx_model?id=${id}`);
const pptx_model = await response.json();
return pptx_model;
};
@ -104,7 +105,7 @@ const Header = ({
// Save the presentation data before exporting
await PresentationGenerationApi.updatePresentationContent(presentationData);
const response = await fetch('/api/export-as-pdf', {
const response = await apiFetch('/api/export-as-pdf', {
method: 'POST',
body: JSON.stringify({
id: presentation_id,

View file

@ -35,7 +35,8 @@ export async function GET(request: NextRequest) {
try {
const id = await getPresentationId(request);
[browser, page] = await getBrowserAndPage(id);
const sessionToken = request.cookies.get("session_token")?.value;
[browser, page] = await getBrowserAndPage(id, sessionToken);
const screenshotsDir = getScreenshotsDir();
const { slides, speakerNotes } = await getSlidesAndSpeakerNotes(page);
@ -75,7 +76,10 @@ async function getPresentationId(request: NextRequest) {
return id;
}
async function getBrowserAndPage(id: string): Promise<[Browser, Page]> {
async function getBrowserAndPage(
id: string,
sessionToken: string | undefined
): Promise<[Browser, Page]> {
const browser = await puppeteer.launch({
executablePath: process.env.PUPPETEER_EXECUTABLE_PATH,
headless: true,
@ -99,10 +103,24 @@ async function getBrowserAndPage(id: string): Promise<[Browser, Page]> {
page.setDefaultNavigationTimeout(300000);
page.setDefaultTimeout(300000);
const baseUrl = process.env.PUPPETEER_BASE_URL || `http://localhost:${process.env.PORT || 3000}`;
await page.goto(`${baseUrl}/pdf-maker?id=${id}`, {
waitUntil: "networkidle0",
timeout: 300000,
if (sessionToken) {
await page.setCookie({
name: "session_token",
value: sessionToken,
url: baseUrl,
httpOnly: true,
});
}
await page.goto(`${baseUrl}/ppt-tool/pdf-maker?id=${id}`, {
waitUntil: "domcontentloaded",
timeout: 60000,
});
await page.waitForSelector(
"#presentation-slides-wrapper [data-speaker-note]",
{ timeout: 120000 }
);
return [browser, page];
}

View file

@ -200,7 +200,7 @@ function convertToAutoShapeBox(element: ElementAttributes): PptxAutoShapeBoxMode
shadow,
position,
text_wrap: element.textWrap ?? true,
border_radius: borderRadius || undefined,
border_radius: borderRadius ? Math.round(borderRadius) : undefined,
paragraphs
};
}