diff --git a/templates/types/streaming/express/src/controllers/sandbox.controller.ts b/templates/types/streaming/express/src/controllers/sandbox.controller.ts index e885839f0..1c20ef16f 100644 --- a/templates/types/streaming/express/src/controllers/sandbox.controller.ts +++ b/templates/types/streaming/express/src/controllers/sandbox.controller.ts @@ -117,26 +117,18 @@ async function downloadCellResults( cellResults.map(async (res) => { const formats = res.formats(); // available formats in the result const formatResults = await Promise.all( - formats.map(async (ext) => { - if (ext === "chart") { - // save chart data as json file - const filename = `${crypto.randomUUID()}.json`; + formats + .filter((ext) => ["png", "svg", "jpeg", "pdf"].includes(ext)) + .map(async (ext) => { + const filename = `${crypto.randomUUID()}.${ext}`; + const base64 = res[ext as keyof Result]; + const buffer = Buffer.from(base64, "base64"); const fileurl = await saveDocument( path.join(OUTPUT_DIR, filename), - JSON.stringify(res[ext as keyof Result]), + buffer, ); return { url: fileurl, filename }; - } - - const filename = `${crypto.randomUUID()}.${ext}`; - const base64 = res[ext as keyof Result]; - const buffer = Buffer.from(base64, "base64"); - const fileurl = await saveDocument( - path.join(OUTPUT_DIR, filename), - buffer, - ); - return { url: fileurl, filename }; - }), + }), ); return formatResults; }), diff --git a/templates/types/streaming/nextjs/app/api/sandbox/route.ts b/templates/types/streaming/nextjs/app/api/sandbox/route.ts index c0e08783e..07336ccdc 100644 --- a/templates/types/streaming/nextjs/app/api/sandbox/route.ts +++ b/templates/types/streaming/nextjs/app/api/sandbox/route.ts @@ -135,26 +135,18 @@ async function downloadCellResults( cellResults.map(async (res) => { const formats = res.formats(); // available formats in the result const formatResults = await Promise.all( - formats.map(async (ext) => { - if (ext === "chart") { - // save chart data as json file - const filename = `${crypto.randomUUID()}.json`; + formats + .filter((ext) => ["png", "svg", "jpeg", "pdf"].includes(ext)) + .map(async (ext) => { + const filename = `${crypto.randomUUID()}.${ext}`; + const base64 = res[ext as keyof Result]; + const buffer = Buffer.from(base64, "base64"); const fileurl = await saveDocument( path.join(OUTPUT_DIR, filename), - JSON.stringify(res[ext as keyof Result]), + buffer, ); return { url: fileurl, filename }; - } - - const filename = `${crypto.randomUUID()}.${ext}`; - const base64 = res[ext as keyof Result]; - const buffer = Buffer.from(base64, "base64"); - const fileurl = await saveDocument( - path.join(OUTPUT_DIR, filename), - buffer, - ); - return { url: fileurl, filename }; - }), + }), ); return formatResults; }),