From 97c9dbecd85eeca05573e6d14efa443162ec8db7 Mon Sep 17 00:00:00 2001 From: white_lamb <72876613+by-2020-github@users.noreply.github.com> Date: Sun, 23 Aug 2026 08:54:02 +0800 Subject: [PATCH] fix: avoid double prefix when listing remote WebDAV directory list(remotePath) always re-joined remotePath with baseRemotePath via fullPath(). Callers pass cfg.webdav.remote_path (e.g. /Vol2_Home/codex), which produced a doubled path (/Vol2_Home/codex/Vol2_Home/codex) and an HTTP 404. The error was silently swallowed by .catch(() => []) in api/sync.js and bin/cxsync.js, so the remote file list was always empty: preview always showed 0 files to download, and every sync re-uploaded all local files. Now list() treats a path that is already baseRemotePath (or one of its sub-paths) as absolute and uses it as-is; relative sub-paths still go through fullPath(). --- src/webdav-client.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/webdav-client.js b/src/webdav-client.js index 3c0418e..af5a1c6 100644 --- a/src/webdav-client.js +++ b/src/webdav-client.js @@ -34,11 +34,18 @@ export function createWebDAVClient(webdavConfig) { * 列出远端目录内容(递归) * 注意:不用 deep:true(Depth: infinity),许多服务器出于安全默认拒绝(403), * 改为逐层 Depth:1 递归,兼容性更好。 - * @param {string} remotePath 相对于 remote_path 的路径,默认为根 + * @param {string} remotePath 相对于 remote_path 的路径,默认为根; + * 也接受完整的 remote_path(或其子路径)以避免误传导致路径重复拼接 * @returns {Promise>} */ async list(remotePath = '') { - const target = remotePath ? fullPath(remotePath) : baseRemotePath; + // remotePath 为空 → 列 baseRemotePath 根目录; + // remotePath 已是 baseRemotePath 或其子路径 → 直接使用,避免 fullPath() 二次拼接产生重复前缀 + const target = remotePath + ? (remotePath === baseRemotePath || remotePath.startsWith(baseRemotePath + '/') + ? remotePath + : fullPath(remotePath)) + : baseRemotePath; const files = []; await listRecursive(raw, target, files); return files.map(item => ({