@@ -7,7 +7,8 @@ import { HttpStatus } from '@nestjs/common'
77import { FileTaskEvent } from '../events/file-events'
88import { FILE_OPERATION } from '../constants/operations'
99import { writeFromStream } from './files'
10- import { DownloadFileDto } from '../dto/file-operations.dto'
10+ import type { DownloadFileDto } from '../dto/file-operations.dto'
11+ import type { DownloadFileContentInfo , DownloadFileOptions } from '../interfaces/download-file.interface'
1112
1213const parts = [
1314 // IPv4 loopback (127.0.0.0/8)
@@ -39,8 +40,20 @@ export async function downloadFile(
3940 http : HttpService ,
4041 downloadDto : DownloadFileDto ,
4142 dstPath : string ,
42- options ?: { space ?: SpaceEnv ; getContentInfo ?: boolean }
43- ) {
43+ options : { space ?: SpaceEnv ; getContentInfo : true }
44+ ) : Promise < DownloadFileContentInfo >
45+ export async function downloadFile (
46+ http : HttpService ,
47+ downloadDto : DownloadFileDto ,
48+ dstPath : string ,
49+ options ?: { space ?: SpaceEnv ; getContentInfo ?: false | undefined }
50+ ) : Promise < void >
51+ export async function downloadFile (
52+ http : HttpService ,
53+ downloadDto : DownloadFileDto ,
54+ dstPath : string ,
55+ options ?: DownloadFileOptions
56+ ) : Promise < void | DownloadFileContentInfo > {
4457 // dto must be validated by the caller
4558 const headRes : AxiosResponse = await http . axiosRef ( { method : HTTP_METHOD . HEAD , url : downloadDto . url , maxRedirects : 1 } )
4659 if ( regExpPrivateIP . test ( headRes . request . socket . remoteAddress ) ) {
@@ -51,7 +64,11 @@ export async function downloadFile(
5164 // attempt to retrieve the Content-Length header
5265 const contentLength = 'content-length' in headRes . headers ? Number ( headRes . headers [ 'content-length' ] ) || null : null
5366 if ( options ?. getContentInfo ) {
54- return { contentLength : contentLength , contentType : `${ headRes . headers [ 'content-type' ] } ` , lastModified : headRes . headers [ 'last-modified' ] }
67+ return {
68+ contentLength : contentLength ,
69+ contentType : `${ headRes . headers [ 'content-type' ] } ` ,
70+ lastModified : headRes . headers [ 'last-modified' ] as string | undefined
71+ } satisfies DownloadFileContentInfo
5572 }
5673
5774 if ( ! contentLength ) {
0 commit comments