Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

Add file upload enabled check and new i18n message (#28946)

Gen Sato7fead6a9da86
diff --git a/web/app/components/base/file-uploader/hooks.ts b/web/app/components/base/file-uploader/hooks.ts
index 521ecdbafda..baef5ff7d8e 100644
--- a/web/app/components/base/file-uploader/hooks.ts
+++ b/web/app/components/base/file-uploader/hooks.ts
@@ -246,6 +246,11 @@ export const useFile = (fileConfig: FileUpload) => {
}, [fileStore])
const handleLocalFileUpload = useCallback((file: File) => {
+ // Check file upload enabled
+ if (!fileConfig.enabled) {
+ notify({ type: 'error', message: t('common.fileUploader.uploadDisabled') })
+ return
+ }
if (!isAllowedFileExtension(file.name, file.type, fileConfig.allowed_file_types || [], fileConfig.allowed_file_extensions || [])) {
notify({ type: 'error', message: `${t('common.fileUploader.fileExtensionNotSupport')} ${file.type}` })
return
@@ -298,30 +303,16 @@ export const useFile = (fileConfig: FileUpload) => {
false,
)
reader.readAsDataURL(file)
- }, [checkSizeLimit, notify, t, handleAddFile, handleUpdateFile, params.token, fileConfig?.allowed_file_types, fileConfig?.allowed_file_extensions])
+ }, [checkSizeLimit, notify, t, handleAddFile, handleUpdateFile, params.token, fileConfig?.allowed_file_types, fileConfig?.allowed_file_extensions, fileConfig?.enabled])
const handleClipboardPasteFile = useCallback((e: ClipboardEvent<HTMLTextAreaElement>) => {
const file = e.clipboardData?.files[0]
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, fileConfig, notify, t])
+ }, [handleLocalFileUpload])
const [isDragActive, setIsDragActive] = useState(false)
const handleDragFileEnter = useCallback((e: React.DragEvent<HTMLElement>) => {
diff --git a/web/i18n/en-US/common.ts b/web/i18n/en-US/common.ts
index 26c6ed89f21..11cc866fded 100644
--- a/web/i18n/en-US/common.ts
+++ b/web/i18n/en-US/common.ts
@@ -743,6 +743,7 @@ const translation = {
pasteFileLinkInvalid: 'Invalid file link',
fileExtensionNotSupport: 'File extension not supported',
fileExtensionBlocked: 'This file type is blocked for security reasons',
+ uploadDisabled: 'File upload is disabled',
},
tag: {
placeholder: 'All Tags',
diff --git a/web/i18n/ja-JP/common.ts b/web/i18n/ja-JP/common.ts
index 984161a1142..2f7bb13fb5a 100644
--- a/web/i18n/ja-JP/common.ts
+++ b/web/i18n/ja-JP/common.ts
@@ -747,6 +747,7 @@ const translation = {
uploadFromComputerReadError: 'ファイルの読み取りに失敗しました。もう一度やり直してください。',
fileExtensionNotSupport: 'ファイル拡張子はサポートされていません',
pasteFileLinkInvalid: '無効なファイルリンク',
+ uploadDisabled: 'ファイルアップロードは無効です',
fileExtensionBlocked: 'このファイルタイプは、セキュリティ上の理由でブロックされています',
},
license: {