Skip to content

Commit 94a06de

Browse files
committed
feat: Validates file types before upload
Prevents uploading of unsupported file types to the chat. Displays an alert message to the user when attempting to upload unsupported files, informing them about the acceptable file formats. Only processes supported files, improving the user experience.
1 parent 8d8372b commit 94a06de

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

tools/server/webui/src/lib/components/app/chat/ChatScreen/ChatScreen.svelte

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { parseFilesToMessageExtras } from '$lib/utils/convert-files-to-extra';
33
import { processFilesToChatUploaded } from '$lib/utils/process-uploaded-files';
44
import { serverStore } from '$lib/stores/server.svelte';
5+
import { isFileTypeSupported } from '$lib/constants/supported-file-types';
56
import { ChatForm, ChatScreenHeader, ChatMessages, ServerInfo } from '$lib/components/app';
67
import {
78
activeMessages,
@@ -116,8 +117,30 @@
116117
}
117118
118119
async function processFiles(files: File[]) {
119-
const processed = await processFilesToChatUploaded(files);
120-
uploadedFiles = [...uploadedFiles, ...processed];
120+
const supportedFiles: File[] = [];
121+
const unsupportedFiles: File[] = [];
122+
123+
for (const file of files) {
124+
if (isFileTypeSupported(file.name, file.type)) {
125+
supportedFiles.push(file);
126+
} else {
127+
unsupportedFiles.push(file);
128+
}
129+
}
130+
131+
if (unsupportedFiles.length > 0) {
132+
const fileNames = unsupportedFiles.map(f => f.name).join(', ');
133+
const message = unsupportedFiles.length === 1
134+
? `The file "${fileNames}" is not supported. Please upload images (JPG, PNG, GIF, WebP, SVG), audio files (MP3, WAV), PDFs, or text files.`
135+
: `The following files are not supported: ${fileNames}. Please upload images (JPG, PNG, GIF, WebP, SVG), audio files (MP3, WAV), PDFs, or text files.`;
136+
137+
alert(message);
138+
}
139+
140+
if (supportedFiles.length > 0) {
141+
const processed = await processFilesToChatUploaded(supportedFiles);
142+
uploadedFiles = [...uploadedFiles, ...processed];
143+
}
121144
}
122145
123146
function scrollChatToBottom(behavior: ScrollBehavior = 'smooth') {

0 commit comments

Comments
 (0)