Add file type validation to paste upload (#28017)

This commit is contained in:
Gen Sato 2025-11-12 20:27:56 +09:00 committed by GitHub
parent 6026bd873b
commit 19c92fd670
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 15 additions and 1 deletions

View File

@ -305,9 +305,23 @@ export const useFile = (fileConfig: FileUpload) => {
const text = e.clipboardData?.getData('text/plain')
if (file && !text) {
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])
}, [handleLocalFileUpload, fileConfig, notify, t])
const [isDragActive, setIsDragActive] = useState(false)
const handleDragFileEnter = useCallback((e: React.DragEvent<HTMLElement>) => {