From 10573072ff5e07b1f24353a67c101c0f28f82f27 Mon Sep 17 00:00:00 2001 From: inubimambo Date: Wed, 9 Jul 2025 21:42:08 +0800 Subject: [PATCH] Fix: RAG can get corrupted upon uploading other file types --- public/js/main.js | 55 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/public/js/main.js b/public/js/main.js index 0667f63..9906645 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -53,9 +53,60 @@ function initializeFileUpload() { function showFileInfo(file) { if (fileName && fileSize && fileInfo) { - fileName.textContent = file.name; - fileSize.textContent = `(${formatFileSize(file.size)})`; + // Define allowed file types for client-side validation + const allowedExtensions = ['.pdf', '.txt', '.doc', '.docx', '.xlsx', '.xls', '.md', '.json', '.csv', '.xml']; + const allowedMimeTypes = [ + 'application/pdf', + 'text/plain', + 'text/markdown', + 'text/csv', + 'text/xml', + 'application/xml', + 'application/json', + 'application/msword', + 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', + 'application/vnd.ms-excel', + 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' + ]; + + // Get file extension + const fileExtension = '.' + file.name.split('.').pop().toLowerCase(); + const fileMimeType = file.type.toLowerCase(); + + // Check if file type is allowed + const isExtensionAllowed = allowedExtensions.includes(fileExtension); + const isMimeTypeAllowed = allowedMimeTypes.includes(fileMimeType) || fileMimeType === ''; + + if (!isExtensionAllowed) { + // Show error for invalid file type + fileInfo.innerHTML = ` +
+ + Invalid file type! "${fileExtension}" files are not supported. +
Only document files (PDF, Word, Excel, text files) are allowed to prevent RAG corruption. +
+ `; + fileInfo.classList.remove('d-none'); + uploadBtn.disabled = true; + return; + } + + // Show valid file info + fileInfo.innerHTML = ` +
+ + ${file.name} + (${formatFileSize(file.size)}) +
+ + + File type supported for AI processing + +
+
+ `; fileInfo.classList.remove('d-none'); + uploadBtn.disabled = false; } }