@@ -12,7 +12,7 @@ import { v4 as uuidv4 } from "uuid";
1212import * as mime from "mime-types" ;
1313
1414export interface FileMetadata {
15- size ? : number ;
15+ size : number ;
1616 contentType ?: string ;
1717 lastModified ?: Date ;
1818 name ?: string ;
@@ -91,15 +91,15 @@ async function getRemoteFileStreamAndMetadata(url: string): Promise<{ stream: Re
9191
9292 const headers = response . headers ;
9393 const contentLength = headers . get ( "content-length" ) ;
94- const contentType = headers . get ( "content-type" ) || undefined ;
9594 const lastModified = headers . get ( "last-modified" )
9695 ? new Date ( headers . get ( "last-modified" ) ! )
9796 : undefined ;
9897 const etag = headers . get ( "etag" ) || undefined ;
9998 const urlObj = new URL ( url ) ;
100- const name = urlObj . pathname . split ( "/" ) . pop ( ) || undefined ;
99+ const name = basename ( urlObj . pathname ) ;
100+ const contentType = headers . get ( "content-type" ) || mime . lookup ( urlObj . pathname ) || undefined ;
101101
102- const baseMetadata : FileMetadata = {
102+ const baseMetadata = {
103103 contentType,
104104 lastModified,
105105 name,
@@ -123,7 +123,7 @@ async function getRemoteFileStreamAndMetadata(url: string): Promise<{ stream: Re
123123 return await downloadToTemporaryFile ( response , baseMetadata ) ;
124124}
125125
126- async function downloadToTemporaryFile ( response : Response , baseMetadata : FileMetadata ) : Promise < { stream : Readable ; metadata : FileMetadata } > {
126+ async function downloadToTemporaryFile ( response : Response , baseMetadata : Partial < FileMetadata > ) : Promise < { stream : Readable ; metadata : FileMetadata } > {
127127 // Generate unique temporary file path
128128 const tempFileName = `file-stream-${ uuidv4 ( ) } ` ;
129129 const tempFilePath = join ( tmpdir ( ) , tempFileName ) ;
0 commit comments