diff --git a/app/components/dify-dataset-manager/document-upload.tsx b/app/components/dify-dataset-manager/document-upload.tsx index b7467c3..4b39b8d 100644 --- a/app/components/dify-dataset-manager/document-upload.tsx +++ b/app/components/dify-dataset-manager/document-upload.tsx @@ -22,14 +22,16 @@ import { Spin, Tooltip, Upload, + message, } from 'antd'; import { useEffect, useState } from 'react'; import type { Segment } from '~/api/dify-dataset/type'; import { useDocumentUpload } from '~/hooks/dify-dataset-manager/document-upload'; import type { DocumentUploadProps, UploadedDocument } from '~/types/dify-dataset-manager/document-upload'; -import { SUPPORTED_FORMATS } from '~/types/dify-dataset-manager/document-upload'; +import { SUPPORTED_ACCEPT, SUPPORTED_FILE_EXTENSIONS, SUPPORTED_FORMATS } from '~/types/dify-dataset-manager/document-upload'; const { Dragger } = Upload; +const MAX_FILE_SIZE_MB = 15; /** * 文档上传组件 @@ -121,9 +123,24 @@ export default function DocumentUpload({ false} + beforeUpload={(file) => { + const lowerName = file.name.toLowerCase(); + const isSupported = SUPPORTED_FILE_EXTENSIONS.some((ext) => lowerName.endsWith(ext)); + if (!isSupported) { + message.error(`仅支持上传 ${SUPPORTED_FORMATS} 格式的文件`); + return Upload.LIST_IGNORE; + } + + const isWithinLimit = file.size / 1024 / 1024 <= MAX_FILE_SIZE_MB; + if (!isWithinLimit) { + message.error(`单个文件大小不能超过 ${MAX_FILE_SIZE_MB}MB`); + return Upload.LIST_IGNORE; + } + + return false; + }} multiple={true} - accept=".txt,.md,.mdx,.pdf,.html,.htm,.xlsx,.xls,.docx,.csv,.vtt,.properties" + accept={SUPPORTED_ACCEPT} showUploadList={false} >

diff --git a/app/types/dify-dataset-manager/document-upload.ts b/app/types/dify-dataset-manager/document-upload.ts index aaf8fbb..541e7ce 100644 --- a/app/types/dify-dataset-manager/document-upload.ts +++ b/app/types/dify-dataset-manager/document-upload.ts @@ -65,7 +65,9 @@ export const INDEXING_STATUS_CONFIG: Record