@@ -88,6 +88,19 @@ export const GET = withRouteHandler(
8888
8989 logger . info ( 'Exporting markdown' , { id, imageCount : imageIds . length } )
9090
91+ if ( imageIds . length === 0 ) {
92+ const mdName = safeFilename ( record . originalName )
93+ const mdBytes = Buffer . from ( mdContent , 'utf-8' )
94+ return new NextResponse ( new Uint8Array ( mdBytes ) , {
95+ status : 200 ,
96+ headers : {
97+ 'Content-Type' : 'text/markdown; charset=utf-8' ,
98+ 'Content-Disposition' : `attachment; filename="${ mdName } "` ,
99+ 'Content-Length' : String ( mdBytes . length ) ,
100+ } ,
101+ } )
102+ }
103+
91104 const fetchResults = await Promise . allSettled (
92105 imageIds . map ( async ( imageId ) => {
93106 const imgRecord = await getFileMetadataById ( imageId )
@@ -122,19 +135,6 @@ export const GET = withRouteHandler(
122135 assetMap . set ( imageId , { filename, buffer } )
123136 }
124137
125- if ( imageIds . length === 0 ) {
126- const mdName = safeFilename ( record . originalName )
127- const mdBytes = Buffer . from ( mdContent , 'utf-8' )
128- return new NextResponse ( new Uint8Array ( mdBytes ) , {
129- status : 200 ,
130- headers : {
131- 'Content-Type' : 'text/markdown; charset=utf-8' ,
132- 'Content-Disposition' : `attachment; filename="${ mdName } "` ,
133- 'Content-Length' : String ( mdBytes . length ) ,
134- } ,
135- } )
136- }
137-
138138 for ( const [ imageId , asset ] of assetMap ) {
139139 const escapedId = imageId . replace ( / [ . * + ? ^ $ { } ( ) | [ \] \\ ] / g, '\\$&' )
140140 const replacement = `./assets/${ asset . filename } `
0 commit comments