MCPcopy
hub / github.com/guangzhengli/ChatFiles / validateFile

Function validateFile

components/Chat/Upload.tsx:51–66  ·  view source on GitHub ↗
(file: File)

Source from the content-addressed store, hash-verified

49 };
50
51 const validateFile = (file: File) => {
52 console.log(`upload file size: ${humanFileSize(file.size)}`);
53 console.log(`file max size: ${humanFileSize(CHAT_FILES_MAX_SIZE)}`);
54 if (CHAT_FILES_MAX_SIZE != 0 && file.size > CHAT_FILES_MAX_SIZE) {
55 handleUploadError(`Please select a file smaller than ${humanFileSize(CHAT_FILES_MAX_SIZE)}`);
56 return false;
57 }
58
59 console.log(`upload file type: ${file.name.split('.').pop()!}`);
60 if (!validateFileType(file.name.split('.').pop()!)) {
61 handleUploadError(`Please upload file of these types: ${supportFileType}`);
62 return false;
63 }
64
65 return true;
66 };
67
68 const supportFileType = "pdf, epub, docx, txt, md, csv, json, zip";
69

Callers 1

handleFileFunction · 0.85

Calls 3

humanFileSizeFunction · 0.90
handleUploadErrorFunction · 0.85
validateFileTypeFunction · 0.85

Tested by

no test coverage detected