revert back the webdav path func
This commit is contained in:
parent
28b99557a8
commit
b877228415
|
@ -173,52 +173,6 @@ const getWebdavPath = (fileOrFolderPath: string, remoteBaseDir: string) => {
|
||||||
return key;
|
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) => {
|
const getNormPath = (fileOrFolderPath: string, remoteBaseDir: string) => {
|
||||||
if (
|
if (
|
||||||
!(
|
!(
|
||||||
|
@ -235,8 +189,7 @@ const getNormPath = (fileOrFolderPath: string, remoteBaseDir: string) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
const fromWebdavItemToEntity = (x: FileStat, remoteBaseDir: string) => {
|
const fromWebdavItemToEntity = (x: FileStat, remoteBaseDir: string) => {
|
||||||
const { shortPath, prefix } = extractPrefix(x.filename);
|
let key = getNormPath(x.filename, remoteBaseDir);
|
||||||
let key = getNormPath(shortPath, remoteBaseDir);
|
|
||||||
if (x.type === "directory" && !key.endsWith("/")) {
|
if (x.type === "directory" && !key.endsWith("/")) {
|
||||||
key = `${key}/`;
|
key = `${key}/`;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue