Skip to content

Commit 765cf2a

Browse files
committed
fix: Replace replaceAll with the replace function
1 parent 33762f2 commit 765cf2a

File tree

2 files changed

+7
-48
lines changed

2 files changed

+7
-48
lines changed

ui/src/components/ai-chat/component/chat-input-operate/index.vue

Lines changed: 6 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@
287287
</div>
288288
</template>
289289
<script setup lang="ts">
290-
import { ref, computed, onMounted, nextTick, watch } from 'vue'
290+
import { ref, computed, onMounted, nextTick, watch, reactive } from 'vue'
291291
import Recorder from 'recorder-core'
292292
import TouchChat from './TouchChat.vue'
293293
import applicationApi from '@/api/application'
@@ -392,17 +392,7 @@ const checkMaxFilesLimit = () => {
392392
uploadOtherList.value.length
393393
)
394394
}
395-
const file_name_eq = (str: string, str1: string) => {
396-
return (
397-
str.replaceAll(' ', '') === str1.replaceAll(' ', '') ||
398-
decodeHtmlEntities(str) === decodeHtmlEntities(str1)
399-
)
400-
}
401-
function decodeHtmlEntities(str: string) {
402-
const tempDiv = document.createElement('div')
403-
tempDiv.innerHTML = str
404-
return tempDiv.textContent || tempDiv.innerText || ''
405-
}
395+
406396
const uploadFile = async (file: any, fileList: any) => {
407397
const { maxFiles, fileLimit } = props.applicationDetails.file_upload_setting
408398
// 单次上传文件数量限制
@@ -427,6 +417,7 @@ const uploadFile = async (file: any, fileList: any) => {
427417
const formData = new FormData()
428418
formData.append('file', file.raw, file.name)
429419
//
420+
file = reactive(file)
430421
const extension = file.name.split('.').pop().toUpperCase() // 获取文件后缀名并转为小写
431422
if (imageExtensions.includes(extension)) {
432423
uploadImageList.value.push(file)
@@ -460,41 +451,9 @@ const uploadFile = async (file: any, fileList: any) => {
460451
)
461452
.then((response) => {
462453
fileList.splice(0, fileList.length)
463-
uploadImageList.value.forEach((file: any) => {
464-
const f = response.data.filter((f: any) => file_name_eq(f.name, file.name))
465-
if (f.length > 0) {
466-
file.url = f[0].url
467-
file.file_id = f[0].file_id
468-
}
469-
})
470-
uploadDocumentList.value.forEach((file: any) => {
471-
const f = response.data.filter((f: any) => file_name_eq(f.name, file.name))
472-
if (f.length > 0) {
473-
file.url = f[0].url
474-
file.file_id = f[0].file_id
475-
}
476-
})
477-
uploadAudioList.value.forEach((file: any) => {
478-
const f = response.data.filter((f: any) => file_name_eq(f.name, file.name))
479-
if (f.length > 0) {
480-
file.url = f[0].url
481-
file.file_id = f[0].file_id
482-
}
483-
})
484-
uploadVideoList.value.forEach((file: any) => {
485-
const f = response.data.filter((f: any) => file_name_eq(f.name, file.name))
486-
if (f.length > 0) {
487-
file.url = f[0].url
488-
file.file_id = f[0].file_id
489-
}
490-
})
491-
uploadOtherList.value.forEach((file: any) => {
492-
const f = response.data.filter((f: any) => file_name_eq(f.name, file.name))
493-
if (f.length > 0) {
494-
file.url = f[0].url
495-
file.file_id = f[0].file_id
496-
}
497-
})
454+
file.url = response.data[0].url
455+
file.file_id = response.data[0].file_id
456+
498457
if (!inputValue.value && uploadImageList.value.length > 0) {
499458
inputValue.value = t('chat.uploadFile.imageMessage')
500459
}

ui/src/components/ai-chat/component/prologue-content/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const prologue = computed(() => {
5858
]
5959
let _temp = temp
6060
for (const index in tag_list) {
61-
_temp = _temp.replaceAll(tag_list[index], '')
61+
_temp = _temp.replace(new RegExp(tag_list[index], 'g'), '')
6262
}
6363
const quick_question_list = _temp.match(/-\s.+/g)
6464
let result = temp

0 commit comments

Comments
 (0)