From 4946968577aa45ab33c9e7d29877cb9995518faa Mon Sep 17 00:00:00 2001 From: Alfonsxh Date: Tue, 15 Jul 2025 17:52:51 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=94=B9=E8=BF=9B=20OAuth=20=E4=BC=9A?= =?UTF-8?q?=E8=AF=9D=E7=AE=A1=E7=90=86=E5=AF=B9=E8=B1=A1=E5=BA=8F=E5=88=97?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 setOAuthSession 中添加复杂对象序列化逻辑 - 在 getOAuthSession 中添加 proxy 字段反序列化 - 增强对 proxy 配置等复杂对象的存储支持 - 添加错误处理,解析失败时将 proxy 设为 null 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- src/models/redis.js | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/models/redis.js b/src/models/redis.js index 33edf935..35986696 100644 --- a/src/models/redis.js +++ b/src/models/redis.js @@ -444,13 +444,36 @@ class RedisClient { // 🔗 OAuth会话管理 async setOAuthSession(sessionId, sessionData, ttl = 600) { // 10分钟过期 const key = `oauth:${sessionId}`; - await this.client.hset(key, sessionData); + + // 序列化复杂对象,特别是 proxy 配置 + const serializedData = {}; + for (const [dataKey, value] of Object.entries(sessionData)) { + if (typeof value === 'object' && value !== null) { + serializedData[dataKey] = JSON.stringify(value); + } else { + serializedData[dataKey] = value; + } + } + + await this.client.hset(key, serializedData); await this.client.expire(key, ttl); } async getOAuthSession(sessionId) { const key = `oauth:${sessionId}`; - return await this.client.hgetall(key); + const data = await this.client.hgetall(key); + + // 反序列化 proxy 字段 + if (data.proxy) { + try { + data.proxy = JSON.parse(data.proxy); + } catch (error) { + // 如果解析失败,设置为 null + data.proxy = null; + } + } + + return data; } async deleteOAuthSession(sessionId) {