Fixes and improvements #14
@@ -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 = `
|
||||
<div class="alert alert-danger">
|
||||
<i class="fas fa-exclamation-triangle me-2"></i>
|
||||
<strong>Invalid file type!</strong> "${fileExtension}" files are not supported.
|
||||
<br><small>Only document files (PDF, Word, Excel, text files) are allowed to prevent RAG corruption.</small>
|
||||
</div>
|
||||
`;
|
||||
fileInfo.classList.remove('d-none');
|
||||
uploadBtn.disabled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
// Show valid file info
|
||||
fileInfo.innerHTML = `
|
||||
<div class="alert alert-info">
|
||||
<i class="fas fa-file me-2"></i>
|
||||
<span>${file.name}</span>
|
||||
<span class="text-muted ms-2">(${formatFileSize(file.size)})</span>
|
||||
<div class="mt-2">
|
||||
<small class="text-success">
|
||||
<i class="fas fa-check-circle me-1"></i>
|
||||
File type supported for AI processing
|
||||
</small>
|
||||
</div>
|
||||
</div>
|
||||
`;
|
||||
fileInfo.classList.remove('d-none');
|
||||
uploadBtn.disabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user