Эх сурвалжийг харах

fix: 云端数据库密码留空时沿用已保存值

之前设置页密码框留空会把空串当成新密码提交,pg 触发
"SASL: client password must be a string"(看起来像密码错误)。
现在空串/纯空白视为「保持原密码」,只有显式输入新密码才覆盖。
liangzhao 1 долоо хоног өмнө
parent
commit
d96785018e

+ 4 - 1
server/routes/settings.js

@@ -216,7 +216,10 @@ function register(app, ctx) {
         port: Number(body.pgPort) || current.port || 5432,
         database: String(body.pgDatabase !== undefined ? body.pgDatabase : (current.database || '')).trim(),
         user: String(body.pgUser !== undefined ? body.pgUser : (current.user || '')).trim(),
-        password: (pw !== undefined && pw !== null && !String(pw).includes('••')) ? String(pw) : (current.password || ''),
+        // 留空 = 沿用已保存密码(否则空串会覆盖密码,触发 SASL 'password must be a string')
+        password: (pw !== undefined && pw !== null && String(pw).trim() !== '' && !String(pw).includes('••'))
+          ? String(pw)
+          : (current.password || ''),
         ssl: body.pgSsl !== undefined ? !!body.pgSsl : !!current.ssl,
         schema: String(body.pgSchema || current.schema || 'public'),
         max: current.max || 5,