@@ -5,7 +5,7 @@ import { enqueueSnackbar as enqueueSnackbarAction, closeSnackbar as closeSnackba
5
5
import parser from 'html-react-parser'
6
6
7
7
// material-ui
8
- import { Button , Box } from '@mui/material'
8
+ import { Button , Box , Typography } from '@mui/material'
9
9
import { IconX , IconBulb } from '@tabler/icons-react'
10
10
11
11
// Project import
@@ -22,6 +22,18 @@ const message = `Uploaded files will be parsed as strings and sent to the LLM. I
22
22
<br />
23
23
Refer <a href='https://docs.flowiseai.com/using-flowise/uploads#files' target='_blank'>docs</a> for more details.`
24
24
25
+ const availableFileTypes = [
26
+ { name : 'CSS' , ext : 'text/css' } ,
27
+ { name : 'CSV' , ext : 'text/csv' } ,
28
+ { name : 'HTML' , ext : 'text/html' } ,
29
+ { name : 'JSON' , ext : 'application/json' } ,
30
+ { name : 'Markdown' , ext : 'text/markdown' } ,
31
+ { name : 'PDF' , ext : 'application/pdf' } ,
32
+ { name : 'SQL' , ext : 'application/sql' } ,
33
+ { name : 'Text File' , ext : 'text/plain' } ,
34
+ { name : 'XML' , ext : 'application/xml' }
35
+ ]
36
+
25
37
const FileUpload = ( { dialogProps } ) => {
26
38
const dispatch = useDispatch ( )
27
39
@@ -31,16 +43,27 @@ const FileUpload = ({ dialogProps }) => {
31
43
const closeSnackbar = ( ...args ) => dispatch ( closeSnackbarAction ( ...args ) )
32
44
33
45
const [ fullFileUpload , setFullFileUpload ] = useState ( false )
46
+ const [ allowedFileTypes , setAllowedFileTypes ] = useState ( [ ] )
34
47
const [ chatbotConfig , setChatbotConfig ] = useState ( { } )
35
48
36
49
const handleChange = ( value ) => {
37
50
setFullFileUpload ( value )
38
51
}
39
52
53
+ const handleAllowedFileTypesChange = ( event ) => {
54
+ const { checked, value } = event . target
55
+ if ( checked ) {
56
+ setAllowedFileTypes ( ( prev ) => [ ...prev , value ] )
57
+ } else {
58
+ setAllowedFileTypes ( ( prev ) => prev . filter ( ( item ) => item !== value ) )
59
+ }
60
+ }
61
+
40
62
const onSave = async ( ) => {
41
63
try {
42
64
const value = {
43
- status : fullFileUpload
65
+ status : fullFileUpload ,
66
+ allowedUploadFileTypes : allowedFileTypes . join ( ',' )
44
67
}
45
68
chatbotConfig . fullFileUpload = value
46
69
@@ -82,6 +105,9 @@ const FileUpload = ({ dialogProps }) => {
82
105
}
83
106
84
107
useEffect ( ( ) => {
108
+ /* backward compatibility - by default, allow all */
109
+ const allowedFileTypes = availableFileTypes . map ( ( fileType ) => fileType . ext )
110
+ setAllowedFileTypes ( allowedFileTypes )
85
111
if ( dialogProps . chatflow ) {
86
112
if ( dialogProps . chatflow . chatbotConfig ) {
87
113
try {
@@ -90,6 +116,10 @@ const FileUpload = ({ dialogProps }) => {
90
116
if ( chatbotConfig . fullFileUpload ) {
91
117
setFullFileUpload ( chatbotConfig . fullFileUpload . status )
92
118
}
119
+ if ( chatbotConfig . fullFileUpload ?. allowedUploadFileTypes ) {
120
+ const allowedFileTypes = chatbotConfig . fullFileUpload . allowedUploadFileTypes . split ( ',' )
121
+ setAllowedFileTypes ( allowedFileTypes )
122
+ }
93
123
} catch ( e ) {
94
124
setChatbotConfig ( { } )
95
125
}
@@ -135,8 +165,44 @@ const FileUpload = ({ dialogProps }) => {
135
165
</ div >
136
166
< SwitchInput label = 'Enable Full File Upload' onChange = { handleChange } value = { fullFileUpload } />
137
167
</ Box >
138
- { /* TODO: Allow selection of allowed file types*/ }
139
- < StyledButton style = { { marginBottom : 10 , marginTop : 10 } } variant = 'contained' onClick = { onSave } >
168
+
169
+ < Typography sx = { { fontSize : 14 , fontWeight : 500 , marginBottom : 1 } } > Allow Uploads of Type</ Typography >
170
+ < div
171
+ style = { {
172
+ display : 'grid' ,
173
+ gridTemplateColumns : 'repeat(auto-fill, minmax(250px, 1fr))' ,
174
+ gap : 15 ,
175
+ padding : 10 ,
176
+ width : '100%' ,
177
+ marginBottom : '10px'
178
+ } }
179
+ >
180
+ { availableFileTypes . map ( ( fileType ) => (
181
+ < div
182
+ key = { fileType . ext }
183
+ style = { {
184
+ display : 'flex' ,
185
+ flexDirection : 'row' ,
186
+ alignItems : 'center' ,
187
+ justifyContent : 'start'
188
+ } }
189
+ >
190
+ < input
191
+ type = 'checkbox'
192
+ id = { fileType . ext }
193
+ name = { fileType . ext }
194
+ checked = { allowedFileTypes . indexOf ( fileType . ext ) !== - 1 }
195
+ value = { fileType . ext }
196
+ disabled = { ! fullFileUpload }
197
+ onChange = { handleAllowedFileTypesChange }
198
+ />
199
+ < label htmlFor = { fileType . ext } style = { { marginLeft : 10 } } >
200
+ { fileType . name } ({ fileType . ext } )
201
+ </ label >
202
+ </ div >
203
+ ) ) }
204
+ </ div >
205
+ < StyledButton style = { { marginBottom : 10 , marginTop : 20 } } variant = 'contained' onClick = { onSave } >
140
206
Save
141
207
</ StyledButton >
142
208
</ >
0 commit comments