diff --git a/packages/trpc/src/services/mount.service.ts b/packages/trpc/src/services/mount.service.ts index 72ed485..61f3786 100644 --- a/packages/trpc/src/services/mount.service.ts +++ b/packages/trpc/src/services/mount.service.ts @@ -151,12 +151,13 @@ export const mountService = { } catch (e) { return { ok: false, message: e instanceof Error ? e.message : "地址不合法" }; } - // 编辑时密码留空:复用已存密文测连,避免每次重填 + // 编辑时密码留空:复用已存密文测连,避免每次重填;用户名缺省也从挂载读取 let password = input.password; + let username = input.username; let usedStored = false; - if (!password && input.mountId && userId) { + if (input.mountId && userId) { const existing = await mountDao.getByIdForUser(input.mountId, userId); - if (existing?.secretEnc) { + if (!password && existing?.secretEnc) { try { password = decryptSecret(existing.secretEnc); usedStored = true; @@ -164,11 +165,12 @@ export const mountService = { // 密钥不一致等,退回空密码 } } + if (!username && existing?.username) username = existing.username; } try { const client = createWebdav({ baseUrl: input.baseUrl, - username: input.username, + username, password, }); const root = normalizeWebdavPath(input.rootPath || "/");