fix: 去掉.doc分段支持

This commit is contained in:
shaohuzhang1 2024-04-10 17:29:09 +08:00
commit de1d1c2c2c
3 changed files with 17 additions and 8 deletions

View File

@ -29,7 +29,8 @@ class TextSplitHandle(BaseSplitHandle):
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

View File

@ -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))
}
/*

View File

@ -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"
@ -29,7 +29,7 @@
</p>
<div class="upload__decoration">
<p>
支持格式TXTMarkdownPDFDOCDOCX每次最多上传50个文件每个文件不超过 100MB
支持格式TXTMarkdownPDFDOCX每次最多上传50个文件每个文件不超过 100MB
</p>
<p>若使用高级分段建议上传前规范文件的分段标识</p>
</div>
@ -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()
@ -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 = () => {