Skip to content

Commit

Permalink
fix: Dealing with the issue of filename exceeding 128 characters when…
Browse files Browse the repository at this point in the history
… uploading documents(#2144)

Co-authored-by: wangdan-fit2cloud <dan.wang@fit2cloud.com>
  • Loading branch information
shaohuzhang1 and wangdan-fit2cloud authored Feb 9, 2025
1 parent 761b686 commit d9abe8d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
10 changes: 9 additions & 1 deletion ui/src/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { number } from 'echarts'

export function toThousands(num: any) {
return num?.toString().replace(/\d+/, function (n: any) {
return n.replace(/(\d)(?=(?:\d{3})+$)/g, '$1,')
Expand Down Expand Up @@ -51,7 +53,6 @@ export function getImgUrl(name: string) {
}
// 是否是白名单后缀
export function isRightType(name: string, type: string) {
console.log(name, type)
return typeList[type].includes(fileType(name).toLowerCase())
}

Expand Down Expand Up @@ -100,3 +101,10 @@ export function downloadByURL(url: string, name: string) {
a.click()
document.body.removeChild(a)
}

// 截取文件名
export function cutFilename(filename: string, num: number) {
const lastIndex = filename.lastIndexOf('.')
const suffix = lastIndex === -1 ? '' : filename.substring(lastIndex + 1)
return filename.substring(0, num - suffix.length - 1) + '.' + suffix
}
14 changes: 10 additions & 4 deletions ui/src/views/dataset/component/SetRules.vue
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
<script setup lang="ts">
import { ref, computed, onMounted, reactive, watch } from 'vue'
import ParagraphPreview from '@/views/dataset/component/ParagraphPreview.vue'
import { cutFilename } from '@/utils/utils'
import documentApi from '@/api/document'
import useStore from '@/stores'
import type { KeyValue } from '@/api/type/common'
Expand Down Expand Up @@ -186,8 +187,12 @@ function splitDocument() {
.postSplitDocument(fd)
.then((res: any) => {
const list = res.data
if (checkedConnect.value) {
list.map((item: any) => {
list.map((item: any) => {
if (item.name.length > 128) {
item.name = cutFilename(item.name, 128)
}
if (checkedConnect.value) {
item.content.map((v: any) => {
v['problem_list'] = v.title.trim()
? [
Expand All @@ -197,8 +202,9 @@ function splitDocument() {
]
: []
})
})
}
}
})
paragraphList.value = list
loading.value = false
})
Expand Down
20 changes: 16 additions & 4 deletions ui/src/views/dataset/component/UploadComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,11 @@
</em>
</p>
<div class="upload__decoration">
<p>{{ $t('views.document.upload.formats') }}TXT、Markdown、PDF、DOCX、HTML、XLS、XLSX、CSV、ZIP</p>
<p>
{{
$t('views.document.upload.formats')
}}TXT、Markdown、PDF、DOCX、HTML、XLS、XLSX、CSV、ZIP
</p>
</div>
</div>
</el-upload>
Expand Down Expand Up @@ -207,7 +211,9 @@ const form = ref({
})
const rules = reactive({
fileList: [{ required: true, message: t('views.document.upload.requiredMessage'), trigger: 'change' }]
fileList: [
{ required: true, message: t('views.document.upload.requiredMessage'), trigger: 'change' }
]
})
const FormRef = ref()
Expand All @@ -217,11 +223,17 @@ watch(form.value, (value) => {
})
function downloadTemplate(type: string) {
documentApi.exportQATemplate(`${type}${t('views.document.upload.template')}.${type == 'csv' ? type : 'xlsx'}`, type)
documentApi.exportQATemplate(
`${type}${t('views.document.upload.template')}.${type == 'csv' ? type : 'xlsx'}`,
type
)
}
function downloadTableTemplate(type: string) {
documentApi.exportTableTemplate(`${type}${t('views.document.upload.template')}.${type == 'csv' ? type : 'xlsx'}`, type)
documentApi.exportTableTemplate(
`${type}${t('views.document.upload.template')}.${type == 'csv' ? type : 'xlsx'}`,
type
)
}
function radioChange() {
Expand Down

0 comments on commit d9abe8d

Please sign in to comment.