fix minor bug of webdav

This commit is contained in:
fyears 2024-01-10 01:34:45 +08:00
parent afc5670313
commit 71e25be28e

View File

@ -148,8 +148,12 @@ const getWebdavPath = (fileOrFolderPath: string, remoteBaseDir: string) => {
if (fileOrFolderPath === "/" || fileOrFolderPath === "") { if (fileOrFolderPath === "/" || fileOrFolderPath === "") {
// special // special
key = `/${remoteBaseDir}/`; key = `/${remoteBaseDir}/`;
} } else if (fileOrFolderPath.startsWith("/")) {
if (!fileOrFolderPath.startsWith("/")) { log.warn(
`why the path ${fileOrFolderPath} starts with '/'? but we just go on.`
);
key = `/${remoteBaseDir}${fileOrFolderPath}`;
} else {
key = `/${remoteBaseDir}/${fileOrFolderPath}`; key = `/${remoteBaseDir}/${fileOrFolderPath}`;
} }
return key; return key;
@ -314,12 +318,17 @@ export const getWebdavClient = (
); );
}; };
/**
*
* @param client
* @param remotePath It should be prefix-ed already
* @returns
*/
export const getRemoteMeta = async ( export const getRemoteMeta = async (
client: WrappedWebdavClient, client: WrappedWebdavClient,
fileOrFolderPath: string remotePath: string
) => { ) => {
await client.init(); await client.init();
const remotePath = getWebdavPath(fileOrFolderPath, client.remoteBaseDir);
// log.info(`remotePath = ${remotePath}`); // log.info(`remotePath = ${remotePath}`);
const res = (await client.client.stat(remotePath, { const res = (await client.client.stat(remotePath, {
details: false, details: false,
@ -549,8 +558,8 @@ export const deleteFromRemote = async (
await client.client.deleteFile(remoteFileName); await client.client.deleteFile(remoteFileName);
// log.info(`delete ${remoteFileName} succeeded`); // log.info(`delete ${remoteFileName} succeeded`);
} catch (err) { } catch (err) {
console.error("some error while deleting"); log.error("some error while deleting");
log.info(err); log.error(err);
} }
}; };