Skip to content

Commit

Permalink
fix: 去掉.doc分段支持
Browse files Browse the repository at this point in the history
  • Loading branch information
shaohuzhang1 committed Apr 10, 2024
2 parents fb7abb4 + 8b31fd6 commit de1d1c2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
3 changes: 2 additions & 1 deletion apps/common/handle/impl/text_split_handle.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ def support(self, file, get_buffer):
if file_name.endswith(".md") or file_name.endswith('.txt'):
return True
result = detect(buffer)
if result['encoding'] != 'ascii' and result['confidence'] > 0.5:
if result['encoding'] is not None and result['confidence'] is not None and result['encoding'] != 'ascii' and \
result['confidence'] > 0.5:
return True
return False

Expand Down
11 changes: 7 additions & 4 deletions ui/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,21 @@ export const randomId = function () {
*/
export function fileType(name: string) {
const suffix = name.split('.')

return suffix[suffix.length - 1] === 'docx' ? 'doc' : suffix[suffix.length - 1]
return suffix[suffix.length - 1]
}

/*
获得文件对应图片
*/
export function getImgUrl(name: string) {
const typeList = ['txt', 'pdf', 'doc', 'csv', 'md']
const type = typeList.includes(fileType(name)) ? fileType(name) : 'unknow'
const type = isRightType(name) ? fileType(name) : 'unknow'
return new URL(`../assets/${type}-icon.svg`, import.meta.url).href
}
// 是否是白名单后缀
export function isRightType(name: string) {
const typeList = ['txt', 'pdf', 'docx', 'csv', 'md']
return typeList.includes(fileType(name))
}

/*
从指定数组中过滤出对应的对象
Expand Down
11 changes: 8 additions & 3 deletions ui/src/views/dataset/component/UploadComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
action="#"
:auto-upload="false"
:show-file-list="false"
accept=".txt, .md, .csv, .log, .doc, .docx, .pdf"
accept=".txt, .md, .csv, .log, .docx, .pdf"
:limit="50"
:on-exceed="onExceed"
:on-change="filehandleChange"
Expand All @@ -29,7 +29,7 @@
</p>
<div class="upload__decoration">
<p>
支持格式:TXT、Markdown、PDF、DOC、DOCX,每次最多上传50个文件,每个文件不超过 100MB
支持格式:TXT、Markdown、PDF、DOCX,每次最多上传50个文件,每个文件不超过 100MB
</p>
<p>若使用【高级分段】建议上传前规范文件的分段标识</p>
</div>
Expand Down Expand Up @@ -61,7 +61,7 @@
<script setup lang="ts">
import { ref, reactive, onUnmounted, onMounted, computed, watch } from 'vue'
import type { UploadFile, UploadFiles } from 'element-plus'
import { filesize, getImgUrl } from '@/utils/utils'
import { filesize, getImgUrl, isRightType } from '@/utils/utils'
import { MsgError } from '@/utils/message'
import useStore from '@/stores'
const { dataset } = useStore()
Expand Down Expand Up @@ -91,6 +91,11 @@ const filehandleChange = (file: any, fileList: UploadFiles) => {
fileList.splice(-1, 1) //移除当前超出大小的文件
return false
}
if (!isRightType(file?.name)) {
MsgError('文件格式不支持')
fileList.splice(-1, 1)
return false
}
}
const onExceed = () => {
Expand Down

0 comments on commit de1d1c2

Please sign in to comment.