Merge pull request #234 from tanaer/bugfix

Fixes: Gemini账户调度状态在页面刷新后与实际设置不符
This commit is contained in:
Wesley Liddick
2025-08-11 17:08:59 +08:00
committed by GitHub
2 changed files with 21 additions and 5 deletions

View File

@@ -2308,16 +2308,21 @@ router.put(
return res.status(404).json({ error: 'Account not found' }) return res.status(404).json({ error: 'Account not found' })
} }
// 将字符串 'true'/'false' 转换为布尔值,然后取反 // 现在 account.schedulable 已经是布尔值了,直接取反即可
const currentSchedulable = account.schedulable === 'true' const newSchedulable = !account.schedulable
const newSchedulable = !currentSchedulable
await geminiAccountService.updateAccount(accountId, { schedulable: String(newSchedulable) }) await geminiAccountService.updateAccount(accountId, { schedulable: String(newSchedulable) })
// 验证更新是否成功,重新获取账户信息
const updatedAccount = await geminiAccountService.getAccount(accountId)
const actualSchedulable = updatedAccount ? updatedAccount.schedulable : newSchedulable
logger.success( 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) { } catch (error) {
logger.error('❌ Failed to toggle Gemini account schedulable status:', error) logger.error('❌ Failed to toggle Gemini account schedulable status:', error)
return res return res

View File

@@ -363,6 +363,9 @@ async function getAccount(accountId) {
} }
} }
// 转换 schedulable 字符串为布尔值(与 claudeConsoleAccountService 保持一致)
accountData.schedulable = accountData.schedulable !== 'false' // 默认为true只有明确设置为'false'才为false
return accountData return accountData
} }
@@ -386,6 +389,11 @@ async function updateAccount(accountId, updates) {
updates.proxy = updates.proxy ? JSON.stringify(updates.proxy) : '' updates.proxy = updates.proxy ? JSON.stringify(updates.proxy) : ''
} }
// 处理 schedulable 字段,确保正确转换为字符串存储
if (updates.schedulable !== undefined) {
updates.schedulable = updates.schedulable.toString()
}
// 加密敏感字段 // 加密敏感字段
if (updates.geminiOauth) { if (updates.geminiOauth) {
updates.geminiOauth = encrypt( updates.geminiOauth = encrypt(
@@ -517,6 +525,9 @@ async function getAllAccounts() {
} }
} }
// 转换 schedulable 字符串为布尔值(与 getAccount 保持一致)
accountData.schedulable = accountData.schedulable !== 'false' // 默认为true只有明确设置为'false'才为false
// 不解密敏感字段,只返回基本信息 // 不解密敏感字段,只返回基本信息
accounts.push({ accounts.push({
...accountData, ...accountData,