mirror of https://github.com/langgenius/dify.git
Add file type validation to paste upload (#28017)
This commit is contained in:
parent
6026bd873b
commit
19c92fd670
|
|
@ -305,9 +305,23 @@ export const useFile = (fileConfig: FileUpload) => {
|
||||||
const text = e.clipboardData?.getData('text/plain')
|
const text = e.clipboardData?.getData('text/plain')
|
||||||
if (file && !text) {
|
if (file && !text) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
|
|
||||||
|
const allowedFileTypes = fileConfig.allowed_file_types || []
|
||||||
|
const fileType = getSupportFileType(file.name, file.type, allowedFileTypes?.includes(SupportUploadFileTypes.custom))
|
||||||
|
const isFileTypeAllowed = allowedFileTypes.includes(fileType)
|
||||||
|
|
||||||
|
// Check if file type is in allowed list
|
||||||
|
if (!isFileTypeAllowed || !fileConfig.enabled) {
|
||||||
|
notify({
|
||||||
|
type: 'error',
|
||||||
|
message: t('common.fileUploader.fileExtensionNotSupport'),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
handleLocalFileUpload(file)
|
handleLocalFileUpload(file)
|
||||||
}
|
}
|
||||||
}, [handleLocalFileUpload])
|
}, [handleLocalFileUpload, fileConfig, notify, t])
|
||||||
|
|
||||||
const [isDragActive, setIsDragActive] = useState(false)
|
const [isDragActive, setIsDragActive] = useState(false)
|
||||||
const handleDragFileEnter = useCallback((e: React.DragEvent<HTMLElement>) => {
|
const handleDragFileEnter = useCallback((e: React.DragEvent<HTMLElement>) => {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue