fix: 统一文档解析文件格式校验

- 统一知识库和工作流支持格式并增加前后端上传拦截

- 拒绝 XLS 与伪装 XLSX,避免空内容解析成功
This commit is contained in:
2026-09-02 19:15:01 +08:00
parent 36acf37976
commit c3673ece46
24 changed files with 658 additions and 101 deletions

View File

@@ -10,6 +10,7 @@ import { useAccessStore } from '@easyflow/stores';
import { UploadFilled } from '@element-plus/icons-vue';
import { ElIcon, ElMessage, ElUpload } from 'element-plus';
import { DocumentParseFilePolicy } from '#/utils/document-parse-file-policy';
import {
normalizeUploadError,
resolveUploadPath,
@@ -28,7 +29,6 @@ const props = defineProps({
const emit = defineEmits(['success', 'error', 'onChange']);
const MAX_FILE_SIZE_BYTES = 100 * 1024 * 1024;
const ACCEPTED_FILE_TYPES = '.txt,.pdf,.docx,.md,.pptx,.xlsx';
const accessStore = useAccessStore();
const headers = ref({
'easyflow-token': accessStore.accessToken,
@@ -54,12 +54,18 @@ const handleError: UploadProps['onError'] = (error) => {
emit('error', normalizedError);
};
const beforeUpload: UploadProps['beforeUpload'] = (rawFile) => {
if (rawFile.size <= MAX_FILE_SIZE_BYTES) {
return true;
const beforeUpload: UploadProps['beforeUpload'] = async (rawFile) => {
try {
await DocumentParseFilePolicy.validateFiles([rawFile]);
} catch (error: any) {
ElMessage.warning(error?.message || $t('message.notSupported'));
return false;
}
ElMessage.warning($t('message.upload.fileTooLarge'));
return false;
if (rawFile.size > MAX_FILE_SIZE_BYTES) {
ElMessage.warning($t('message.upload.fileTooLarge'));
return false;
}
return true;
};
// 文件状态变化回调
@@ -97,7 +103,7 @@ defineExpose({
drag
:headers="headers"
:action="`${apiURL}${props.action}`"
:accept="ACCEPTED_FILE_TYPES"
:accept="DocumentParseFilePolicy.accept"
:before-upload="beforeUpload"
:on-success="handleSuccess"
:on-error="handleError"
@@ -111,7 +117,9 @@ defineExpose({
<div class="flex flex-col gap-1">
<span class="text-base">{{ $t('message.upload.title') }}</span>
<span class="text-muted-foreground text-sm">{{
$t('message.upload.description')
$t('message.upload.description', {
types: DocumentParseFilePolicy.supportedTypeLabel,
})
}}</span>
</div>
</ElUpload>