Skip to content

Commit 02c7e11

Browse files
Binx98liuruibin
authored andcommitted
fix: correct file removal logic that bypassed size limit on folder upload
1 parent 306e376 commit 02c7e11

3 files changed

Lines changed: 32 additions & 8 deletions

File tree

ui/src/components/dynamics-form/items/upload/LocalFileUpload.vue

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,24 +86,32 @@ const loading = ref<boolean>(false)
8686
const UploadRef = ref()
8787
// 上传on-change事件
8888
const fileHandleChange = (file: any, fileList: UploadFiles) => {
89+
// 按文件唯一标识精确定位并移除当前文件
90+
// 注意:不能使用 splice(-1, 1) 盲删末尾元素,文件夹上传时会误删正常文件而放走超限文件
91+
const removeCurrentFile = () => {
92+
const index = fileList.findIndex((item: any) => item.uid === file.uid)
93+
if (index !== -1) {
94+
fileList.splice(index, 1)
95+
}
96+
}
8997
//1、判断文件大小是否合法,文件限制不能大于100M
9098
const isLimit = file?.size / 1024 / 1024 < file_size_limit.value
9199
if (!isLimit) {
92100
MsgError(t('views.document.tip.fileLimitSizeTip1') + file_size_limit.value + 'MB')
93-
fileList.splice(-1, 1) //移除当前超出大小的文件
101+
removeCurrentFile() //移除当前超出大小的文件
94102
return false
95103
}
96104
if (!file_type_list.value.includes(fileType(file.name).toLocaleUpperCase())) {
97105
if (file?.name !== '.DS_Store') {
98106
MsgError(t('views.document.upload.errorMessage2'))
99107
}
100-
fileList.splice(-1, 1)
108+
removeCurrentFile()
101109
return false
102110
}
103111
104112
if (file?.size === 0) {
105113
MsgError(t('views.document.upload.errorMessage3'))
106-
fileList.splice(-1, 1)
114+
removeCurrentFile()
107115
return false
108116
}
109117
upload(file.raw, loading).then((ok: any) => {

ui/src/views/document/upload/UploadComponent.vue

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -281,24 +281,32 @@ function deleteFile(index: number | string) {
281281
282282
// 上传on-change事件
283283
const fileHandleChange = (file: any, fileList: UploadFiles) => {
284+
// 按文件唯一标识精确定位并移除当前文件
285+
// 注意:不能使用 splice(-1, 1) 盲删末尾元素,文件夹上传时会误删正常文件而放走超限文件
286+
const removeCurrentFile = () => {
287+
const index = fileList.findIndex((item: any) => item.uid === file.uid)
288+
if (index !== -1) {
289+
fileList.splice(index, 1)
290+
}
291+
}
284292
//1、判断文件大小是否合法,文件限制不能大于100M
285293
const isLimit = file?.size / 1024 / 1024 < file_size_limit.value
286294
if (!isLimit) {
287295
MsgError(t('views.document.tip.fileLimitSizeTip1') + file_size_limit.value + 'MB')
288-
fileList.splice(-1, 1) //移除当前超出大小的文件
296+
removeCurrentFile() //移除当前超出大小的文件
289297
return false
290298
}
291299
292300
if (!isRightType(file?.name, form.value.fileType)) {
293301
if (file?.name !== '.DS_Store') {
294302
MsgError(t('views.document.upload.errorMessage2'))
295303
}
296-
fileList.splice(-1, 1)
304+
removeCurrentFile()
297305
return false
298306
}
299307
if (file?.size === 0) {
300308
MsgError(t('views.document.upload.errorMessage3'))
301-
fileList.splice(-1, 1)
309+
removeCurrentFile()
302310
return false
303311
}
304312
}

ui/src/views/tool/SkillToolFormDrawer.vue

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,17 +354,25 @@ function deleteInitField(index: any) {
354354
}
355355
356356
const fileHandleChange = (file: any, fileList: UploadFiles) => {
357+
// 按文件唯一标识精确定位并移除当前文件
358+
// 注意:不能使用 splice(-1, 1) 盲删末尾元素,文件夹上传时会误删正常文件而放走超限文件
359+
const removeCurrentFile = () => {
360+
const index = fileList.findIndex((item: any) => item.uid === file.uid)
361+
if (index !== -1) {
362+
fileList.splice(index, 1)
363+
}
364+
}
357365
//1、判断文件大小是否合法,文件限制不能大于100M
358366
const isLimit = file?.size / 1024 / 1024 < file_size_limit.value
359367
if (!isLimit) {
360368
MsgError(t('views.document.tip.fileLimitSizeTip1') + file_size_limit.value + 'MB')
361-
fileList.splice(-1, 1) //移除当前超出大小的文件
369+
removeCurrentFile() //移除当前超出大小的文件
362370
return false
363371
}
364372
365373
if (file?.size === 0) {
366374
MsgError(t('views.document.upload.errorMessage3'))
367-
fileList.splice(-1, 1)
375+
removeCurrentFile()
368376
return false
369377
}
370378
if (fileList.length > 1) {

0 commit comments

Comments
 (0)