mirror of
https://github.com/1Panel-dev/MaxKB.git
synced 2025-12-26 01:33:05 +00:00
fix: Upload a file in the application dialogue, with a file name containing HTML character entities. After uploading, the file_id of the file is empty #3070 (#3119)
This commit is contained in:
parent
ce2ab322f6
commit
adc5af9cef
|
|
@ -392,7 +392,17 @@ const checkMaxFilesLimit = () => {
|
||||||
uploadOtherList.value.length
|
uploadOtherList.value.length
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
const file_name_eq = (str: string, str1: string) => {
|
||||||
|
return (
|
||||||
|
str.replaceAll(' ', '') === str1.replaceAll(' ', '') ||
|
||||||
|
decodeHtmlEntities(str) === decodeHtmlEntities(str1)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
function decodeHtmlEntities(str: string) {
|
||||||
|
const tempDiv = document.createElement('div')
|
||||||
|
tempDiv.innerHTML = str
|
||||||
|
return tempDiv.textContent || tempDiv.innerText || ''
|
||||||
|
}
|
||||||
const uploadFile = async (file: any, fileList: any) => {
|
const uploadFile = async (file: any, fileList: any) => {
|
||||||
const { maxFiles, fileLimit } = props.applicationDetails.file_upload_setting
|
const { maxFiles, fileLimit } = props.applicationDetails.file_upload_setting
|
||||||
// 单次上传文件数量限制
|
// 单次上传文件数量限制
|
||||||
|
|
@ -418,7 +428,6 @@ const uploadFile = async (file: any, fileList: any) => {
|
||||||
formData.append('file', file.raw, file.name)
|
formData.append('file', file.raw, file.name)
|
||||||
//
|
//
|
||||||
const extension = file.name.split('.').pop().toUpperCase() // 获取文件后缀名并转为小写
|
const extension = file.name.split('.').pop().toUpperCase() // 获取文件后缀名并转为小写
|
||||||
console.log(documentExtensions)
|
|
||||||
if (imageExtensions.includes(extension)) {
|
if (imageExtensions.includes(extension)) {
|
||||||
uploadImageList.value.push(file)
|
uploadImageList.value.push(file)
|
||||||
} else if (documentExtensions.includes(extension)) {
|
} else if (documentExtensions.includes(extension)) {
|
||||||
|
|
@ -452,45 +461,35 @@ console.log(documentExtensions)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
fileList.splice(0, fileList.length)
|
fileList.splice(0, fileList.length)
|
||||||
uploadImageList.value.forEach((file: any) => {
|
uploadImageList.value.forEach((file: any) => {
|
||||||
const f = response.data.filter(
|
const f = response.data.filter((f: any) => file_name_eq(f.name, file.name))
|
||||||
(f: any) => f.name.replaceAll(' ', '') === file.name.replaceAll(' ', '')
|
|
||||||
)
|
|
||||||
if (f.length > 0) {
|
if (f.length > 0) {
|
||||||
file.url = f[0].url
|
file.url = f[0].url
|
||||||
file.file_id = f[0].file_id
|
file.file_id = f[0].file_id
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
uploadDocumentList.value.forEach((file: any) => {
|
uploadDocumentList.value.forEach((file: any) => {
|
||||||
const f = response.data.filter(
|
const f = response.data.filter((f: any) => file_name_eq(f.name, file.name))
|
||||||
(f: any) => f.name.replaceAll(' ', '') == file.name.replaceAll(' ', '')
|
|
||||||
)
|
|
||||||
if (f.length > 0) {
|
if (f.length > 0) {
|
||||||
file.url = f[0].url
|
file.url = f[0].url
|
||||||
file.file_id = f[0].file_id
|
file.file_id = f[0].file_id
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
uploadAudioList.value.forEach((file: any) => {
|
uploadAudioList.value.forEach((file: any) => {
|
||||||
const f = response.data.filter(
|
const f = response.data.filter((f: any) => file_name_eq(f.name, file.name))
|
||||||
(f: any) => f.name.replaceAll(' ', '') === file.name.replaceAll(' ', '')
|
|
||||||
)
|
|
||||||
if (f.length > 0) {
|
if (f.length > 0) {
|
||||||
file.url = f[0].url
|
file.url = f[0].url
|
||||||
file.file_id = f[0].file_id
|
file.file_id = f[0].file_id
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
uploadVideoList.value.forEach((file: any) => {
|
uploadVideoList.value.forEach((file: any) => {
|
||||||
const f = response.data.filter(
|
const f = response.data.filter((f: any) => file_name_eq(f.name, file.name))
|
||||||
(f: any) => f.name.replaceAll(' ', '') === file.name.replaceAll(' ', '')
|
|
||||||
)
|
|
||||||
if (f.length > 0) {
|
if (f.length > 0) {
|
||||||
file.url = f[0].url
|
file.url = f[0].url
|
||||||
file.file_id = f[0].file_id
|
file.file_id = f[0].file_id
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
uploadOtherList.value.forEach((file: any) => {
|
uploadOtherList.value.forEach((file: any) => {
|
||||||
const f = response.data.filter(
|
const f = response.data.filter((f: any) => file_name_eq(f.name, file.name))
|
||||||
(f: any) => f.name.replaceAll(' ', '') === file.name.replaceAll(' ', '')
|
|
||||||
)
|
|
||||||
if (f.length > 0) {
|
if (f.length > 0) {
|
||||||
file.url = f[0].url
|
file.url = f[0].url
|
||||||
file.file_id = f[0].file_id
|
file.file_id = f[0].file_id
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue