@@ -137,12 +137,13 @@ export interface FileValidationError {
137137 * Validate if a file type is supported for document processing
138138 */
139139export function validateFileType ( fileName : string , mimeType : string ) : FileValidationError | null {
140- const extension = path . extname ( fileName ) . toLowerCase ( ) . substring ( 1 ) as SupportedDocumentExtension
140+ const raw = path . extname ( fileName ) . toLowerCase ( ) . substring ( 1 )
141+ const extension = ( / ^ [ a - z 0 - 9 ] + $ / . test ( raw ) ? raw : '' ) as SupportedDocumentExtension
141142
142143 if ( ! SUPPORTED_DOCUMENT_EXTENSIONS . includes ( extension ) ) {
143144 return {
144145 code : 'UNSUPPORTED_FILE_TYPE' ,
145- message : `Unsupported file type: ${ extension } . Supported types are: ${ SUPPORTED_DOCUMENT_EXTENSIONS . join ( ', ' ) } ` ,
146+ message : `Unsupported file type${ extension ? ` : ${ extension } ` : ` for " ${ fileName } "` } . Supported types are: ${ SUPPORTED_DOCUMENT_EXTENSIONS . join ( ', ' ) } ` ,
146147 supportedTypes : [ ...SUPPORTED_DOCUMENT_EXTENSIONS ] ,
147148 }
148149 }
@@ -221,15 +222,16 @@ export function validateMediaFileType(
221222 fileName : string ,
222223 mimeType : string
223224) : FileValidationError | null {
224- const extension = path . extname ( fileName ) . toLowerCase ( ) . substring ( 1 )
225+ const raw = path . extname ( fileName ) . toLowerCase ( ) . substring ( 1 )
226+ const extension = / ^ [ a - z 0 - 9 ] + $ / . test ( raw ) ? raw : ''
225227
226228 const isAudio = SUPPORTED_AUDIO_EXTENSIONS . includes ( extension as SupportedAudioExtension )
227229 const isVideo = SUPPORTED_VIDEO_EXTENSIONS . includes ( extension as SupportedVideoExtension )
228230
229231 if ( ! isAudio && ! isVideo ) {
230232 return {
231233 code : 'UNSUPPORTED_FILE_TYPE' ,
232- message : `Unsupported media file type: ${ extension } . Supported audio types: ${ SUPPORTED_AUDIO_EXTENSIONS . join ( ', ' ) } . Supported video types: ${ SUPPORTED_VIDEO_EXTENSIONS . join ( ', ' ) } ` ,
234+ message : `Unsupported media file type${ extension ? ` : ${ extension } ` : ` for " ${ fileName } "` } . Supported audio types: ${ SUPPORTED_AUDIO_EXTENSIONS . join ( ', ' ) } . Supported video types: ${ SUPPORTED_VIDEO_EXTENSIONS . join ( ', ' ) } ` ,
233235 supportedTypes : [ ...SUPPORTED_AUDIO_EXTENSIONS , ...SUPPORTED_VIDEO_EXTENSIONS ] ,
234236 }
235237 }
0 commit comments