fix: 修复droid账号更新丢失apikey的问题

This commit is contained in:
shaw
2025-10-11 11:23:24 +08:00
parent c56bebdbe5
commit 6c2ef2eef3
3 changed files with 35 additions and 8 deletions

View File

@@ -782,6 +782,8 @@ class DroidAccountService {
} }
const storedAccount = await redis.getDroidAccount(accountId) const storedAccount = await redis.getDroidAccount(accountId)
const hasStoredAccount =
storedAccount && typeof storedAccount === 'object' && Object.keys(storedAccount).length > 0
const sanitizedUpdates = { ...updates } const sanitizedUpdates = { ...updates }
if (typeof sanitizedUpdates.accessToken === 'string') { if (typeof sanitizedUpdates.accessToken === 'string') {
@@ -905,7 +907,7 @@ class DroidAccountService {
// 使用 Redis 中的原始数据获取加密的 API Key 条目 // 使用 Redis 中的原始数据获取加密的 API Key 条目
const existingApiKeyEntries = this._parseApiKeyEntries( const existingApiKeyEntries = this._parseApiKeyEntries(
storedAccount && Object.prototype.hasOwnProperty.call(storedAccount, 'apiKeys') hasStoredAccount && Object.prototype.hasOwnProperty.call(storedAccount, 'apiKeys')
? storedAccount.apiKeys ? storedAccount.apiKeys
: '' : ''
) )
@@ -957,13 +959,29 @@ class DroidAccountService {
encryptedUpdates.accessToken = this._encryptSensitiveData(sanitizedUpdates.accessToken) encryptedUpdates.accessToken = this._encryptSensitiveData(sanitizedUpdates.accessToken)
} }
const baseAccountData = hasStoredAccount ? { ...storedAccount } : { id: accountId }
const updatedData = { const updatedData = {
...account, ...baseAccountData,
...encryptedUpdates, ...encryptedUpdates
refreshToken: }
encryptedUpdates.refreshToken || this._encryptSensitiveData(account.refreshToken),
accessToken: encryptedUpdates.accessToken || this._encryptSensitiveData(account.accessToken), if (!Object.prototype.hasOwnProperty.call(updatedData, 'refreshToken')) {
proxy: encryptedUpdates.proxy updatedData.refreshToken =
hasStoredAccount && Object.prototype.hasOwnProperty.call(storedAccount, 'refreshToken')
? storedAccount.refreshToken
: this._encryptSensitiveData(account.refreshToken)
}
if (!Object.prototype.hasOwnProperty.call(updatedData, 'accessToken')) {
updatedData.accessToken =
hasStoredAccount && Object.prototype.hasOwnProperty.call(storedAccount, 'accessToken')
? storedAccount.accessToken
: this._encryptSensitiveData(account.accessToken)
}
if (!Object.prototype.hasOwnProperty.call(updatedData, 'proxy')) {
updatedData.proxy = hasStoredAccount ? storedAccount.proxy || '' : account.proxy || ''
} }
await redis.setDroidAccount(accountId, updatedData) await redis.setDroidAccount(accountId, updatedData)

View File

@@ -3160,6 +3160,15 @@ const parseProxyResponse = (rawProxy) => {
} }
} }
if (
proxyObject &&
typeof proxyObject === 'object' &&
proxyObject.proxy &&
typeof proxyObject.proxy === 'object'
) {
proxyObject = proxyObject.proxy
}
if (!proxyObject || typeof proxyObject !== 'object') { if (!proxyObject || typeof proxyObject !== 'object') {
return null return null
} }

View File

@@ -2488,7 +2488,7 @@ const filterByGroup = () => {
} }
// 规范化代理配置,支持字符串与对象 // 规范化代理配置,支持字符串与对象
const normalizeProxyData = (proxy) => { function normalizeProxyData(proxy) {
if (!proxy) { if (!proxy) {
return null return null
} }