1313
1414import { handleOptions , responseWithAllowOrigin } from "./cors" ;
1515
16+ function getContentType ( fileExtension : string ) : string | undefined {
17+ switch ( fileExtension ) {
18+ case "json" : return "application/json" ;
19+ case "xml" : return "application/xml" ;
20+ case "zpl" : return "text/plain" ;
21+ case "png" : return "image/png" ;
22+ case "jpg" :
23+ case "jpeg" :
24+ return "image/jpeg" ;
25+ case "gif" : return "image/gif" ;
26+ case "bmp" : return "image/bmp" ;
27+ case "pdf" : return "application/pdf" ;
28+ }
29+ return undefined ;
30+ }
31+
1632/**
1733 * Log conversion request and response data to Cloudflare R2
1834 * @param request
@@ -35,7 +51,7 @@ async function handleConversionLog(request: Request<unknown, IncomingRequestCfPr
3551
3652 // Clone and log request asynchronously
3753 if ( loggingEnabled ) ctx . waitUntil ( Promise . all ( [
38- env . LZ_R2_BUCKET . put ( requestID + `/in.${ sourceFormat } ` , request . clone ( ) . body ) , // TODO: Set content type
54+ env . LZ_R2_BUCKET . put ( requestID + `/in.${ sourceFormat } ` , request . clone ( ) . body , { httpMetadata : { contentType : getContentType ( sourceFormat ) } } ) ,
3955 env . LZ_R2_BUCKET . put ( requestID + '/params.json' , url . searchParams . get ( 'params' ) , { httpMetadata :{ contentType :'application/json' } } )
4056 ] ) ) ;
4157
@@ -44,7 +60,7 @@ async function handleConversionLog(request: Request<unknown, IncomingRequestCfPr
4460
4561 // Clone and log response asynchronously
4662 if ( loggingEnabled ) ctx . waitUntil (
47- env . LZ_R2_BUCKET . put ( requestID + `/out.${ targetFormat } ` , response . clone ( ) . body ) // TODO: Set content type
63+ env . LZ_R2_BUCKET . put ( requestID + `/out.${ targetFormat } ` , response . clone ( ) . body , { httpMetadata : { contentType : getContentType ( targetFormat ) } } )
4864 ) ;
4965
5066 // Return response to client
0 commit comments