This commit is contained in:
jxxghp
2024-05-26 18:38:41 +08:00
parent 7a7a8c923f
commit 7ce0c21b0c
+15 -11
View File
@@ -38,13 +38,13 @@ const downloadDirectories = ref<MediaDirectory[]>([])
// 计算公共路径 // 计算公共路径
function findCommonPath(paths: string[]): string { function findCommonPath(paths: string[]): string {
if (!paths || paths.length === 0) return '/' let commonPath = '/'
if (paths.length === 1) { if (!paths || paths.length === 0) {
if (!paths[0].endsWith('/')) { commonPath = '/'
return paths[0] + '/' } else if (paths.length === 1) {
} commonPath = paths[0]
return paths[0] commonPath = commonPath.replace(/\\/g, '/')
} } else {
const normalizedPaths = paths.map(path => path.replace(/\\/g, '/')) const normalizedPaths = paths.map(path => path.replace(/\\/g, '/'))
const splitPaths = normalizedPaths.map(path => path.split('/')) const splitPaths = normalizedPaths.map(path => path.split('/'))
let commonParts: string[] = [] let commonParts: string[] = []
@@ -56,14 +56,18 @@ function findCommonPath(paths: string[]): string {
break break
} }
} }
let commonPath = commonParts.join('/') commonPath = commonParts.join('/')
if (commonPath.includes(':')) {
commonPath = commonPath.replace('/', '\\')
} }
if (!commonPath.endsWith('/')) { if (!commonPath.endsWith('/')) {
commonPath += '/' commonPath += '/'
} }
return commonPath.length > 0 ? commonPath : paths[0][0] === '/' ? '/' : ''
if (commonPath.includes(':')) {
commonPath = commonPath.replace('/', '\\')
}
return commonPath
} }
// 查询下载目录 // 查询下载目录