fix: 改进 OAuth 会话管理对象序列化

- 在 setOAuthSession 中添加复杂对象序列化逻辑
- 在 getOAuthSession 中添加 proxy 字段反序列化
- 增强对 proxy 配置等复杂对象的存储支持
- 添加错误处理,解析失败时将 proxy 设为 null

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Alfonsxh
2025-07-15 17:52:51 +08:00
parent f2af099e7d
commit 4946968577

View File

@@ -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) {