Files
frontend/apps/sn/app/(with-base-layout)/fileValidation.tsx
T
swcho 5b62171b01 feat:
- 파일 확장자 검증 컴포넌트 구현 및 적용
- 환경청, 시도, 시군구, 하수처리장 입력 검증 컴포넌트 구현 및 적용
- RDII 분석 페이지 하수처리장 선택 로직 에러 수정
2025-07-04 17:26:10 +09:00

48 lines
1.5 KiB
TypeScript

/**
* 파일 확장자 검증 유틸리티
*/
// 파일 확장자 검증 함수
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']
};