88 defaultEndpointsFactory ,
99} from "express-zod-api" ;
1010import { authMiddleware } from "./middlewares" ;
11- import { createReadStream , statSync } from "node:fs" ;
11+ import { createReadStream } from "node:fs" ;
12+ import { stat } from "node:fs/promises" ;
1213import { z } from "zod/v4" ;
1314
1415/** @desc This factory extends the default one by enforcing the authentication using the specified middleware */
@@ -34,12 +35,12 @@ export const fileStreamingEndpointsFactory = new EndpointsFactory(
3435 new ResultHandler ( {
3536 positive : { schema : ez . buffer ( ) , mimeType : "image/*" } ,
3637 negative : { schema : z . string ( ) , mimeType : "text/plain" } ,
37- handler : ( { response, error, output, request : { method } } ) => {
38+ handler : async ( { response, error, output, request : { method } } ) => {
3839 if ( error ) return void response . status ( 400 ) . send ( error . message ) ;
3940 if ( "filename" in output && typeof output . filename === "string" ) {
4041 const target = response . attachment ( output . filename ) ;
4142 if ( method === "HEAD" ) {
42- const { size } = statSync ( output . filename ) ;
43+ const { size } = await stat ( output . filename ) ;
4344 return void target . set ( "Content-Length" , `${ size } ` ) . end ( ) ;
4445 }
4546 createReadStream ( output . filename ) . pipe ( target ) ;
0 commit comments