/** * πŸ“„ File Validation Utility * 파일 ν™•μž₯자 검증 μœ ν‹Έλ¦¬ν‹° * * - 파일 ν™•μž₯자 검증 ν•¨μˆ˜ (단일 및 닀쀑 파일 지원) * - 검증 κ²°κ³Ό νƒ€μž… μ •μ˜ 및 μ—λŸ¬ λ©”μ‹œμ§€ 생성 * - 자주 μ‚¬μš©λ˜λŠ” 파일 ν™•μž₯자 μƒμˆ˜ 제곡 * - 파일 μ—…λ‘œλ“œ μ „ 검증 둜직 κ΅¬ν˜„ * - μ‚¬μš©μž μΉœν™”μ μΈ μ—λŸ¬ λ©”μ‹œμ§€ 좜λ ₯ * - λ‹€μ–‘ν•œ 파일 νƒ€μž…(INP, EXCEL, OFFICE λ“±) 지원 */ // 파일 ν™•μž₯자 검증 ν•¨μˆ˜ 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'] };