/** * 파일 확장자 검증 유틸리티 */ // 파일 확장자 검증 함수 export const validateFileExtension = (file: File, allowedExtensions: string[]): boolean => { const fileName = file.name.toLowerCase(); return allowedExtensions.some(ext => fileName.endsWith(ext.toLowerCase())); }; // 파일 확장자 검증 결과 타입 export interface FileValidationResult { isValid: boolean; errorMessage?: string; } // 파일 검증 설정 타입 export interface FileValidationConfig { file: File; allowedExtensions: string[]; fileDescription: string; } /** * 여러 파일의 확장자를 한 번에 검증하는 함수 * @param validationConfigs 검증할 파일들의 설정 배열 * @returns 검증 결과. 실패 시 첫 번째 에러 메시지 반환 */ export const validateMultipleFiles = (validationConfigs: FileValidationConfig[]): FileValidationResult => { for (const config of validationConfigs) { if (!validateFileExtension(config.file, config.allowedExtensions)) { const allowedExtStr = config.allowedExtensions.join(', '); return { isValid: false, errorMessage: `${config.fileDescription} 파일은 ${allowedExtStr} 확장자만 업로드 가능합니다.` }; } } return { isValid: true }; }; // 자주 사용되는 확장자 상수 export const FILE_EXTENSIONS = { INP: ['.inp'], EXCEL: ['.xls', '.xlsx', '.xlsm', '.xltx'], ALL_OFFICE: ['.xls', '.xlsx', '.xlsm', '.xltx', '.doc', '.docx', '.ppt', '.pptx'] };