Merge branch 'PingChuan' into shiy-login
This commit is contained in:
@@ -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({
|
||||
<Dragger
|
||||
fileList={fileList}
|
||||
onChange={handleFileChange}
|
||||
beforeUpload={() => 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}
|
||||
>
|
||||
<p className="ant-upload-drag-icon">
|
||||
|
||||
Reference in New Issue
Block a user