revert back the webdav path func

This commit is contained in:
fyears 2024-04-05 11:37:03 +08:00
parent 28b99557a8
commit b877228415

View File

@ -173,52 +173,6 @@ const getWebdavPath = (fileOrFolderPath: string, remoteBaseDir: string) => {
return key;
};
function extractPrefix(path: string) {
let startsWithSlash = false;
if (path.startsWith("/")) {
startsWithSlash = true;
path = path.slice(1);
}
let endsWithSlash = false;
if (path.endsWith("/")) {
endsWithSlash = true;
path = path.slice(0, -1);
}
const segments = path.split("/");
const prefix: string[] = [];
let pathString = "/";
let level = 0;
for (let i = 0; i < segments.length; i++) {
const segment = segments[i];
if (segment === ".") {
continue;
} else if (segment === "..") {
level--;
prefix.push(segment);
} else if (level < 0) {
level++;
prefix.push(segment);
} else {
const pathSegments = segments.slice(i);
pathString += pathSegments.join("/");
if (endsWithSlash && pathSegments.length > 0) {
pathString += "/";
}
break;
}
}
const prefixString = (startsWithSlash ? "/" : "") + prefix.join("/");
return {
path: pathString,
prefix: prefixString,
};
}
const getNormPath = (fileOrFolderPath: string, remoteBaseDir: string) => {
if (
!(
@ -235,8 +189,7 @@ const getNormPath = (fileOrFolderPath: string, remoteBaseDir: string) => {
};
const fromWebdavItemToEntity = (x: FileStat, remoteBaseDir: string) => {
const { shortPath, prefix } = extractPrefix(x.filename);
let key = getNormPath(shortPath, remoteBaseDir);
let key = getNormPath(x.filename, remoteBaseDir);
if (x.type === "directory" && !key.endsWith("/")) {
key = `${key}/`;
}