@@ -27,6 +27,8 @@ import { Textarea } from "@/components/ui/textarea";
2727import { conversationService } from "@/services/conversationService" ;
2828import { useConfig } from "@/hooks/useConfig" ;
2929import { extractColorsFromUri } from "@/lib/avatar" ;
30+ import { chatConfig } from "@/const/chatConfig" ;
31+ import { FilePreview } from "@/types/chat" ;
3032
3133import { ChatAgentSelector } from "./chatAgentSelector" ;
3234
@@ -122,33 +124,7 @@ function FileViewer({ file, onClose }: { file: File; onClose: () => void }) {
122124
123125 // Determine if it is a text file
124126 const isTextFile = ( type : string , ext : string ) => {
125- const textTypes = [
126- "text/plain" ,
127- "text/html" ,
128- "text/css" ,
129- "text/javascript" ,
130- "application/json" ,
131- "application/xml" ,
132- "text/markdown" ,
133- ] ;
134-
135- const textExtensions = [
136- "txt" ,
137- "html" ,
138- "htm" ,
139- "css" ,
140- "js" ,
141- "ts" ,
142- "jsx" ,
143- "tsx" ,
144- "json" ,
145- "xml" ,
146- "md" ,
147- "markdown" ,
148- "csv" ,
149- ] ;
150-
151- return textTypes . includes ( type ) || textExtensions . includes ( ext ) ;
127+ return chatConfig . textTypes . includes ( type ) || chatConfig . textExtensions . includes ( ext ) ;
152128 } ;
153129
154130 // Render file content
@@ -240,15 +216,7 @@ function FileViewer({ file, onClose }: { file: File; onClose: () => void }) {
240216 ) ;
241217}
242218
243- // Add file preview type
244- export interface FilePreview {
245- id : string ;
246- file : File ;
247- type : "image" | "file" ;
248- fileType ?: string ;
249- extension ?: string ;
250- previewUrl ?: string ;
251- }
219+
252220
253221// Get file extension
254222const getFileExtension = ( filename : string ) : string => {
@@ -279,58 +247,50 @@ const getFileIcon = (file: File) => {
279247 return < AiFillFileImage size = { iconSize } color = "#8e44ad" /> ;
280248 }
281249
282- // Identify by extension
283- switch ( extension ) {
284- // Document files
285- case "pdf" :
286- return < AiFillFilePdf size = { iconSize } color = "#e74c3c" /> ;
287- case "doc" :
288- case "docx" :
289- return < AiFillFileWord size = { iconSize } color = "#3498db" /> ;
290- case "txt" :
291- return < AiFillFileText size = { iconSize } color = "#7f8c8d" /> ;
292- case "md" :
293- return < AiFillFileMarkdown size = { iconSize } color = "#34495e" /> ;
294-
295- // Table files
296- case "xls" :
297- case "xlsx" :
298- case "csv" :
299- return < AiFillFileExcel size = { iconSize } color = "#27ae60" /> ;
300-
301- // Demo files
302- case "ppt" :
303- case "pptx" :
304- return < AiFillFilePpt size = { iconSize } color = "#e67e22" /> ;
305-
306- // Code files
307- case "html" :
308- case "htm" :
309- return < AiFillHtml5 size = { iconSize } color = "#e67e22" /> ;
310- case "css" :
311- case "js" :
312- case "ts" :
313- case "jsx" :
314- case "tsx" :
315- case "php" :
316- case "py" :
317- case "java" :
318- case "c" :
319- case "cpp" :
320- case "cs" :
321- return < AiFillCode size = { iconSize } color = "#f39c12" /> ;
322- case "json" :
323- return < AiFillCode size = { iconSize } color = "#f1c40f" /> ;
324-
325- // Default file icon
326- default :
327- return < AiFillFileUnknown size = { iconSize } color = "#95a5a6" /> ;
250+ // Check each file type category using config
251+ if ( chatConfig . fileIcons . pdf . includes ( extension ) ) {
252+ return < AiFillFilePdf size = { iconSize } color = "#e74c3c" /> ;
253+ }
254+
255+ if ( chatConfig . fileIcons . word . includes ( extension ) ) {
256+ return < AiFillFileWord size = { iconSize } color = "#3498db" /> ;
257+ }
258+
259+ if ( chatConfig . fileIcons . text . includes ( extension ) ) {
260+ return < AiFillFileText size = { iconSize } color = "#7f8c8d" /> ;
261+ }
262+
263+ if ( chatConfig . fileIcons . markdown . includes ( extension ) ) {
264+ return < AiFillFileMarkdown size = { iconSize } color = "#34495e" /> ;
265+ }
266+
267+ if ( chatConfig . fileIcons . excel . includes ( extension ) ) {
268+ return < AiFillFileExcel size = { iconSize } color = "#27ae60" /> ;
328269 }
270+
271+ if ( chatConfig . fileIcons . powerpoint . includes ( extension ) ) {
272+ return < AiFillFilePpt size = { iconSize } color = "#e67e22" /> ;
273+ }
274+
275+ if ( chatConfig . fileIcons . html . includes ( extension ) ) {
276+ return < AiFillHtml5 size = { iconSize } color = "#e67e22" /> ;
277+ }
278+
279+ if ( chatConfig . fileIcons . code . includes ( extension ) ) {
280+ return < AiFillCode size = { iconSize } color = "#f39c12" /> ;
281+ }
282+
283+ if ( chatConfig . fileIcons . json . includes ( extension ) ) {
284+ return < AiFillCode size = { iconSize } color = "#f1c40f" /> ;
285+ }
286+
287+ // Default file icon
288+ return < AiFillFileUnknown size = { iconSize } color = "#95a5a6" /> ;
329289} ;
330290
331- // File limit constants
332- const MAX_FILE_COUNT = 50 ;
333- const MAX_FILE_SIZE = 5 * 1024 * 1024 ; // Single file maximum 5MB
291+ // File limit constants from config
292+ const MAX_FILE_COUNT = chatConfig . maxFileCount ;
293+ const MAX_FILE_SIZE = chatConfig . maxFileSize ;
334294
335295interface ChatInputProps {
336296 input : string ;
@@ -798,19 +758,17 @@ export function ChatInput({
798758 // Supported image file types
799759 const isImage =
800760 file . type . startsWith ( "image/" ) ||
801- [ "jpg" , "jpeg" , "png" , "gif" , "webp" , "svg" , "bmp" ] . includes ( extension ) ;
761+ chatConfig . imageExtensions . includes ( extension ) ;
802762
803763 // Supported document file types
804764 const isDocument =
805- [ "pdf" , "doc" , "docx" , "xls" , "xlsx" , "ppt" , "pptx" ] . includes (
806- extension
807- ) ||
765+ chatConfig . documentExtensions . includes ( extension ) ||
808766 file . type === "application/pdf" ||
809767 file . type . includes ( "officedocument" ) ;
810768
811769 // Supported text file types
812770 const isSupportedTextFile =
813- [ "md" , "markdown" , "txt" ] . includes ( extension ) ||
771+ chatConfig . supportedTextExtensions . includes ( extension ) ||
814772 file . type === "text/csv" ||
815773 file . type === "text/plain" ;
816774
@@ -821,7 +779,7 @@ export function ChatInput({
821779 newAttachments . push ( {
822780 id : fileId ,
823781 file,
824- type : isImage ? " image" : " file" ,
782+ type : isImage ? chatConfig . filePreviewTypes . image : chatConfig . filePreviewTypes . file ,
825783 fileType : file . type ,
826784 extension,
827785 previewUrl,
@@ -888,7 +846,7 @@ export function ChatInput({
888846
889847 // Handle viewing images
890848 const handleViewImage = ( attachment : FilePreview ) => {
891- if ( attachment . type === " image" && attachment . file ) {
849+ if ( attachment . type === chatConfig . filePreviewTypes . image && attachment . file ) {
892850 // To ensure the preview URL is valid, create a new blob URL
893851 // This avoids using a cached URL that may have expired
894852 const fileReader = new FileReader ( ) ;
@@ -930,7 +888,7 @@ export function ChatInput({
930888 className = "relative group rounded-md border border-slate-200 bg-white shadow-sm hover:shadow transition-all duration-200 w-[190px] mb-1"
931889 >
932890 < div className = "relative p-2 h-[52px] flex items-center" >
933- { attachment . type === " image" ? (
891+ { attachment . type === chatConfig . filePreviewTypes . image ? (
934892 < div className = "flex items-center gap-3 w-full" >
935893 < div
936894 className = "w-10 h-10 flex-shrink-0 overflow-hidden rounded-md cursor-pointer"
@@ -1116,7 +1074,7 @@ export function ChatInput({
11161074 id = "file-upload-regular"
11171075 className = "hidden"
11181076 onChange = { handleFileUpload }
1119- accept = " image/*,.pdf,.doc,.docx,.xls,.xlsx,.ppt,.pptx,.csv,.tsv,.md,.markdown,.txt"
1077+ accept = { ` image/*,${ Object . values ( chatConfig . fileIcons ) . flat ( ) . map ( ext => `. ${ ext } ` ) . join ( ',' ) } ` }
11201078 multiple
11211079 />
11221080 </ Button >
@@ -1234,15 +1192,13 @@ export function ChatInput({
12341192
12351193 const isImage =
12361194 fileType . startsWith ( "image/" ) ||
1237- [ "jpg" , "jpeg" , "png" , "gif" , "webp" , "svg" , "bmp" ] . includes ( extension ) ;
1195+ chatConfig . imageExtensions . includes ( extension ) ;
12381196 const isDocument =
1239- [ "pdf" , "doc" , "docx" , "xls" , "xlsx" , "ppt" , "pptx" ] . includes (
1240- extension
1241- ) ||
1197+ chatConfig . documentExtensions . includes ( extension ) ||
12421198 fileType === "application/pdf" ||
12431199 fileType . includes ( "officedocument" ) ;
12441200 const isSupportedTextFile =
1245- [ "md" , "markdown" , "txt" ] . includes ( extension ) ||
1201+ chatConfig . supportedTextExtensions . includes ( extension ) ||
12461202 fileType === "text/csv" ||
12471203 fileType === "text/plain" ;
12481204
0 commit comments