fix: 修复某些文件上传失败的问题

This commit is contained in:
jmal 2024-03-26 17:56:38 +08:00
parent c837c43c32
commit 92792ff6ba
2 changed files with 16 additions and 3 deletions

View File

@ -119,6 +119,7 @@ import SparkMD5 from 'spark-md5'
import api from '@/api/file-api' import api from '@/api/file-api'
import {formatNetSpeed} from '@/utils/number' import {formatNetSpeed} from '@/utils/number'
import {mapState} from 'vuex' import {mapState} from 'vuex'
import {encodeIfNeeded} from "@/utils/path";
export default { export default {
components: {}, components: {},
@ -334,10 +335,10 @@ export default {
// 上传文件夹 // 上传文件夹
api.uploadFolder({ api.uploadFolder({
isFolder: true, isFolder: true,
folderPath: encodeURI(folder.parent.path), folderPath: encodeIfNeeded(folder.parent.path),
filename: encodeURI(folder.name), filename: encodeIfNeeded(folder.name),
folder: this.$route.query.folder, folder: this.$route.query.folder,
currentDirectory: encodeURI(this.params.currentDirectory), currentDirectory: encodeIfNeeded(this.params.currentDirectory),
username: this.params.username, username: this.params.username,
userId: this.params.userId userId: this.params.userId
}).then(() => { }).then(() => {

View File

@ -26,3 +26,15 @@ export function removePath() {
Cookies.remove(pathListKey) Cookies.remove(pathListKey)
return Cookies.remove(pathKey) return Cookies.remove(pathKey)
} }
function isEncoded(str) {
return /%[0-9A-Fa-f]{2}/.test(str);
}
export function encodeIfNeeded(str) {
if (isEncoded(str)) {
return str;
} else {
return encodeURI(str);
}
}