From 0f66ea7d4a6cf4580fc1150adb575b4cef882993 Mon Sep 17 00:00:00 2001 From: wt Date: Mon, 11 Aug 2025 16:48:34 +0800 Subject: [PATCH] =?UTF-8?q?Fixes:=20Gemini=E8=B4=A6=E6=88=B7=E8=B0=83?= =?UTF-8?q?=E5=BA=A6=E7=8A=B6=E6=80=81=E5=9C=A8=E9=A1=B5=E9=9D=A2=E5=88=B7?= =?UTF-8?q?=E6=96=B0=E5=90=8E=E4=B8=8E=E5=AE=9E=E9=99=85=E8=AE=BE=E7=BD=AE?= =?UTF-8?q?=E4=B8=8D=E7=AC=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/routes/admin.js | 15 ++++++++++----- src/services/geminiAccountService.js | 11 +++++++++++ 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/routes/admin.js b/src/routes/admin.js index 3a53d065..a72479c7 100644 --- a/src/routes/admin.js +++ b/src/routes/admin.js @@ -2308,16 +2308,21 @@ router.put( return res.status(404).json({ error: 'Account not found' }) } - // 将字符串 'true'/'false' 转换为布尔值,然后取反 - const currentSchedulable = account.schedulable === 'true' - const newSchedulable = !currentSchedulable + // 现在 account.schedulable 已经是布尔值了,直接取反即可 + const newSchedulable = !account.schedulable await geminiAccountService.updateAccount(accountId, { schedulable: String(newSchedulable) }) + // 验证更新是否成功,重新获取账户信息 + const updatedAccount = await geminiAccountService.getAccount(accountId) + const actualSchedulable = updatedAccount ? updatedAccount.schedulable : newSchedulable + logger.success( - `🔄 Admin toggled Gemini account schedulable status: ${accountId} -> ${newSchedulable ? 'schedulable' : 'not schedulable'}` + `🔄 Admin toggled Gemini account schedulable status: ${accountId} -> ${actualSchedulable ? 'schedulable' : 'not schedulable'}` ) - return res.json({ success: true, schedulable: newSchedulable }) + + // 返回实际的数据库值,确保前端状态与后端一致 + return res.json({ success: true, schedulable: actualSchedulable }) } catch (error) { logger.error('❌ Failed to toggle Gemini account schedulable status:', error) return res diff --git a/src/services/geminiAccountService.js b/src/services/geminiAccountService.js index d800fb3d..498ab4fe 100644 --- a/src/services/geminiAccountService.js +++ b/src/services/geminiAccountService.js @@ -363,6 +363,9 @@ async function getAccount(accountId) { } } + // 转换 schedulable 字符串为布尔值(与 claudeConsoleAccountService 保持一致) + accountData.schedulable = accountData.schedulable !== 'false' // 默认为true,只有明确设置为'false'才为false + return accountData } @@ -386,6 +389,11 @@ async function updateAccount(accountId, updates) { updates.proxy = updates.proxy ? JSON.stringify(updates.proxy) : '' } + // 处理 schedulable 字段,确保正确转换为字符串存储 + if (updates.schedulable !== undefined) { + updates.schedulable = updates.schedulable.toString() + } + // 加密敏感字段 if (updates.geminiOauth) { updates.geminiOauth = encrypt( @@ -517,6 +525,9 @@ async function getAllAccounts() { } } + // 转换 schedulable 字符串为布尔值(与 getAccount 保持一致) + accountData.schedulable = accountData.schedulable !== 'false' // 默认为true,只有明确设置为'false'才为false + // 不解密敏感字段,只返回基本信息 accounts.push({ ...accountData,