55 lines
1.3 KiB
TypeScript
55 lines
1.3 KiB
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
|
|
import {
|
|
BundledPresentationExportFormat,
|
|
bundledExportPackageAvailable,
|
|
runBundledPresentationExport,
|
|
} from "@/lib/run-bundled-presentation-export";
|
|
|
|
function isValidFormat(value: unknown): value is BundledPresentationExportFormat {
|
|
return value === "pdf" || value === "pptx";
|
|
}
|
|
|
|
export async function POST(req: NextRequest) {
|
|
const { format, id, title } = await req.json();
|
|
|
|
if (!id) {
|
|
return NextResponse.json(
|
|
{ error: "Missing Presentation ID" },
|
|
{ status: 400 }
|
|
);
|
|
}
|
|
|
|
if (!isValidFormat(format)) {
|
|
return NextResponse.json(
|
|
{ error: "Invalid export format" },
|
|
{ status: 400 }
|
|
);
|
|
}
|
|
|
|
try {
|
|
if (!(await bundledExportPackageAvailable())) {
|
|
throw new Error(
|
|
"presentation-export runtime is not available. Run scripts/sync-presentation-export.cjs to install it."
|
|
);
|
|
}
|
|
|
|
const { path: outPath } = await runBundledPresentationExport({
|
|
format,
|
|
presentationId: id,
|
|
title,
|
|
});
|
|
|
|
return NextResponse.json({
|
|
success: true,
|
|
path: outPath,
|
|
});
|
|
} catch (e) {
|
|
const message = e instanceof Error ? e.message : String(e);
|
|
console.error(`[export-presentation:${format}]`, message);
|
|
return NextResponse.json(
|
|
{ error: message, success: false },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|