Skip to content

Commit de1d1c2

Browse files
committed
fix: 去掉.doc分段支持
2 parents fb7abb4 + 8b31fd6 commit de1d1c2

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

apps/common/handle/impl/text_split_handle.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ def support(self, file, get_buffer):
2929
if file_name.endswith(".md") or file_name.endswith('.txt'):
3030
return True
3131
result = detect(buffer)
32-
if result['encoding'] != 'ascii' and result['confidence'] > 0.5:
32+
if result['encoding'] is not None and result['confidence'] is not None and result['encoding'] != 'ascii' and \
33+
result['confidence'] > 0.5:
3334
return True
3435
return False
3536

ui/src/utils/utils.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,21 @@ export const randomId = function () {
3131
*/
3232
export function fileType(name: string) {
3333
const suffix = name.split('.')
34-
35-
return suffix[suffix.length - 1] === 'docx' ? 'doc' : suffix[suffix.length - 1]
34+
return suffix[suffix.length - 1]
3635
}
3736

3837
/*
3938
获得文件对应图片
4039
*/
4140
export function getImgUrl(name: string) {
42-
const typeList = ['txt', 'pdf', 'doc', 'csv', 'md']
43-
const type = typeList.includes(fileType(name)) ? fileType(name) : 'unknow'
41+
const type = isRightType(name) ? fileType(name) : 'unknow'
4442
return new URL(`../assets/${type}-icon.svg`, import.meta.url).href
4543
}
44+
// 是否是白名单后缀
45+
export function isRightType(name: string) {
46+
const typeList = ['txt', 'pdf', 'docx', 'csv', 'md']
47+
return typeList.includes(fileType(name))
48+
}
4649

4750
/*
4851
从指定数组中过滤出对应的对象

ui/src/views/dataset/component/UploadComponent.vue

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
action="#"
1717
:auto-upload="false"
1818
:show-file-list="false"
19-
accept=".txt, .md, .csv, .log, .doc, .docx, .pdf"
19+
accept=".txt, .md, .csv, .log, .docx, .pdf"
2020
:limit="50"
2121
:on-exceed="onExceed"
2222
:on-change="filehandleChange"
@@ -29,7 +29,7 @@
2929
</p>
3030
<div class="upload__decoration">
3131
<p>
32-
支持格式:TXT、Markdown、PDF、DOC、DOCX,每次最多上传50个文件,每个文件不超过 100MB
32+
支持格式:TXT、Markdown、PDF、DOCX,每次最多上传50个文件,每个文件不超过 100MB
3333
</p>
3434
<p>若使用【高级分段】建议上传前规范文件的分段标识</p>
3535
</div>
@@ -61,7 +61,7 @@
6161
<script setup lang="ts">
6262
import { ref, reactive, onUnmounted, onMounted, computed, watch } from 'vue'
6363
import type { UploadFile, UploadFiles } from 'element-plus'
64-
import { filesize, getImgUrl } from '@/utils/utils'
64+
import { filesize, getImgUrl, isRightType } from '@/utils/utils'
6565
import { MsgError } from '@/utils/message'
6666
import useStore from '@/stores'
6767
const { dataset } = useStore()
@@ -91,6 +91,11 @@ const filehandleChange = (file: any, fileList: UploadFiles) => {
9191
fileList.splice(-1, 1) //移除当前超出大小的文件
9292
return false
9393
}
94+
if (!isRightType(file?.name)) {
95+
MsgError('文件格式不支持')
96+
fileList.splice(-1, 1)
97+
return false
98+
}
9499
}
95100
96101
const onExceed = () => {

0 commit comments

Comments
 (0)