MCPcopy Create free account
hub / github.com/ResearAI/AutoFigure / validateFiles

Function validateFiles

frontend/components/chat-input.tsx:52–88  ·  view source on GitHub ↗
(
    newFiles: File[],
    existingCount: number,
)

Source from the content-addressed store, hash-verified

50}
51
52function validateFiles(
53 newFiles: File[],
54 existingCount: number,
55): ValidationResult {
56 const errors: string[] = []
57 const validFiles: File[] = []
58
59 const availableSlots = MAX_FILES - existingCount
60
61 if (availableSlots <= 0) {
62 errors.push(`Maximum ${MAX_FILES} files allowed`)
63 return { validFiles, errors }
64 }
65
66 for (const file of newFiles) {
67 if (validFiles.length >= availableSlots) {
68 errors.push(`Only ${availableSlots} more file(s) allowed`)
69 break
70 }
71 if (!isValidFileType(file)) {
72 errors.push(`"${file.name}" is not a supported file type`)
73 continue
74 }
75 // Only check size for images (PDFs/text files are extracted client-side, so file size doesn't matter)
76 const isExtractedFile = isPdfFile(file) || isTextFile(file)
77 if (!isExtractedFile && file.size > MAX_IMAGE_SIZE) {
78 const maxSizeMB = MAX_IMAGE_SIZE / 1024 / 1024
79 errors.push(
80 `"${file.name}" is ${formatFileSize(file.size)} (exceeds ${maxSizeMB}MB)`,
81 )
82 } else {
83 validFiles.push(file)
84 }
85 }
86
87 return { validFiles, errors }
88}
89
90function showValidationErrors(errors: string[]) {
91 if (errors.length === 0) return

Callers 3

handlePasteFunction · 0.85
handleFileChangeFunction · 0.85
handleDropFunction · 0.85

Calls 4

isPdfFileFunction · 0.90
isTextFileFunction · 0.90
isValidFileTypeFunction · 0.85
formatFileSizeFunction · 0.85

Tested by

no test coverage detected