fix(mount): rootPath is source of truth for WebDAV test

Do not fail when listing / fails; many NAS forbid listing root.
This commit is contained in:
noelorin 2026-09-27 16:50:58 +08:00
parent a7a50f8d0a
commit 7db51693ad
1 changed files with 13 additions and 12 deletions

View File

@ -163,19 +163,20 @@ export const mountService = {
username: input.username,
password,
});
// 1) 先探 WebDAV 根:区分「认证/不是 WebDAV」与「根路径写错」
try {
await listDirectory(client, "/");
} catch (e) {
const msg = describeWebdavError(e);
if (msg.includes("认证失败") || msg.includes("不是 WebDAV") || msg.includes("连接")) {
return { ok: false, message: `${msg}(探测 WebDAV 根路径 / 时失败)` };
}
// 根 400 等:仍继续试 rootPath,部分服务根不可列
}
const root = normalizeWebdavPath(input.rootPath || "/");
try {
await listDirectory(client, root);
return { ok: true, message: "连接成功" };
} catch (e) {
// 根路径失败:再探 / 仅用于补充提示,不以 / 的成败作为结论
// (部分 NAS 禁止列 /,或 / 与共享根权限不同)
try {
await listDirectory(client, "/");
} catch {
// 忽略
}
return { ok: false, message: describeWebdavError(e, root) };
}
} catch (e) {
return { ok: false, message: describeWebdavError(e, input.rootPath || "/") };
}