import express from 'express' ; import { BaseResult } from './BaseResult' ; import { OutgoingHttpHeaders } from 'http' ; export type SendFileResultCallback = ( error : Error | null , req : express . Request , res : express . Response , next : express . NextFunction ) => void ; export class SendFileResult extends BaseResult { constructor ( public readonly filePath , public readonly options = { } , public readonly callback ? , public readonly status = 200 , public readonly headers ? ) { super ( ) ; } async execute ( req , res , next ) { if ( this . headers != null ) { res . set ( this . headers ) ; } if ( this . callback != null ) { const callback = this . callback ; return res . status ( this . status ) . sendFile ( this . filePath , this . options , ( error ) => callback ( error , req , res , next ) ) ; } return res . status ( this . status ) . sendFile ( this . filePath , this . options ) ; } }