From b49c0f38aa1a8c37974b91143bcca8665608c2f8 Mon Sep 17 00:00:00 2001 From: waleed Date: Thu, 7 May 2026 13:50:13 -0700 Subject: [PATCH 1/3] fix(files): skip zip and return plain .md when no embedded images --- apps/sim/app/api/files/export/[id]/route.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/apps/sim/app/api/files/export/[id]/route.ts b/apps/sim/app/api/files/export/[id]/route.ts index ba5b436680..c321871191 100644 --- a/apps/sim/app/api/files/export/[id]/route.ts +++ b/apps/sim/app/api/files/export/[id]/route.ts @@ -86,7 +86,7 @@ export const GET = withRouteHandler( MAX_EMBEDDED_IMAGES ) - logger.info('Exporting markdown with embedded images', { id, imageCount: imageIds.length }) + logger.info('Exporting markdown', { id, imageCount: imageIds.length }) const fetchResults = await Promise.allSettled( imageIds.map(async (imageId) => { @@ -122,6 +122,19 @@ export const GET = withRouteHandler( assetMap.set(imageId, { filename, buffer }) } + if (assetMap.size === 0) { + const mdName = safeFilename(record.originalName) + const mdBytes = Buffer.from(mdContent, 'utf-8') + return new NextResponse(new Uint8Array(mdBytes), { + status: 200, + headers: { + 'Content-Type': 'text/markdown; charset=utf-8', + 'Content-Disposition': `attachment; filename="${mdName}"`, + 'Content-Length': String(mdBytes.length), + }, + }) + } + for (const [imageId, asset] of assetMap) { const escapedId = imageId.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') const replacement = `./assets/${asset.filename}` From 807190d7c3c171aa8b23e35ef4fb5b0285347c6f Mon Sep 17 00:00:00 2001 From: waleed Date: Thu, 7 May 2026 13:58:09 -0700 Subject: [PATCH 2/3] fix(files): use imageIds.length guard instead of assetMap.size --- apps/sim/app/api/files/export/[id]/route.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/sim/app/api/files/export/[id]/route.ts b/apps/sim/app/api/files/export/[id]/route.ts index c321871191..907f2a1830 100644 --- a/apps/sim/app/api/files/export/[id]/route.ts +++ b/apps/sim/app/api/files/export/[id]/route.ts @@ -122,7 +122,7 @@ export const GET = withRouteHandler( assetMap.set(imageId, { filename, buffer }) } - if (assetMap.size === 0) { + if (imageIds.length === 0) { const mdName = safeFilename(record.originalName) const mdBytes = Buffer.from(mdContent, 'utf-8') return new NextResponse(new Uint8Array(mdBytes), { From 26edc0cf7204a513a4d8a72541223190db27e113 Mon Sep 17 00:00:00 2001 From: waleed Date: Thu, 7 May 2026 14:14:03 -0700 Subject: [PATCH 3/3] fix(files): move imageIds.length guard before async fetch to avoid unnecessary work --- apps/sim/app/api/files/export/[id]/route.ts | 26 ++++++++++----------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/apps/sim/app/api/files/export/[id]/route.ts b/apps/sim/app/api/files/export/[id]/route.ts index 907f2a1830..cccbe6af1a 100644 --- a/apps/sim/app/api/files/export/[id]/route.ts +++ b/apps/sim/app/api/files/export/[id]/route.ts @@ -88,6 +88,19 @@ export const GET = withRouteHandler( logger.info('Exporting markdown', { id, imageCount: imageIds.length }) + if (imageIds.length === 0) { + const mdName = safeFilename(record.originalName) + const mdBytes = Buffer.from(mdContent, 'utf-8') + return new NextResponse(new Uint8Array(mdBytes), { + status: 200, + headers: { + 'Content-Type': 'text/markdown; charset=utf-8', + 'Content-Disposition': `attachment; filename="${mdName}"`, + 'Content-Length': String(mdBytes.length), + }, + }) + } + const fetchResults = await Promise.allSettled( imageIds.map(async (imageId) => { const imgRecord = await getFileMetadataById(imageId) @@ -122,19 +135,6 @@ export const GET = withRouteHandler( assetMap.set(imageId, { filename, buffer }) } - if (imageIds.length === 0) { - const mdName = safeFilename(record.originalName) - const mdBytes = Buffer.from(mdContent, 'utf-8') - return new NextResponse(new Uint8Array(mdBytes), { - status: 200, - headers: { - 'Content-Type': 'text/markdown; charset=utf-8', - 'Content-Disposition': `attachment; filename="${mdName}"`, - 'Content-Length': String(mdBytes.length), - }, - }) - } - for (const [imageId, asset] of assetMap) { const escapedId = imageId.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') const replacement = `./assets/${asset.filename}`