From 35fc89b33ebce6acc5ce0fc8d6e16b1470d7c3ba Mon Sep 17 00:00:00 2001 From: mtvpls Date: Thu, 25 Dec 2025 00:39:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=BF=81=E7=A7=BB=E4=B8=A2?= =?UTF-8?q?=E5=A4=B1enabledApis=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/redis-base.db.ts | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/lib/redis-base.db.ts b/src/lib/redis-base.db.ts index c63320d..fe98a43 100644 --- a/src/lib/redis-base.db.ts +++ b/src/lib/redis-base.db.ts @@ -342,7 +342,8 @@ export abstract class BaseRedisStorage implements IStorage { password: string, role: 'owner' | 'admin' | 'user' = 'user', tags?: string[], - oidcSub?: string + oidcSub?: string, + enabledApis?: string[] ): Promise { const hashedPassword = await this.hashPassword(password); const createdAt = Date.now(); @@ -359,6 +360,10 @@ export abstract class BaseRedisStorage implements IStorage { userInfo.tags = JSON.stringify(tags); } + if (enabledApis && enabledApis.length > 0) { + userInfo.enabledApis = JSON.stringify(enabledApis); + } + if (oidcSub) { userInfo.oidcSub = oidcSub; // 创建OIDC映射 @@ -400,6 +405,7 @@ export abstract class BaseRedisStorage implements IStorage { banned: boolean; tags?: string[]; oidcSub?: string; + enabledApis?: string[]; created_at: number; } | null> { const userInfo = await this.withRetry(() => @@ -415,6 +421,7 @@ export abstract class BaseRedisStorage implements IStorage { banned: userInfo.banned === 'true', tags: userInfo.tags ? JSON.parse(userInfo.tags) : undefined, oidcSub: userInfo.oidcSub, + enabledApis: userInfo.enabledApis ? JSON.parse(userInfo.enabledApis) : undefined, created_at: parseInt(userInfo.created_at || '0', 10), }; } @@ -427,6 +434,7 @@ export abstract class BaseRedisStorage implements IStorage { banned?: boolean; tags?: string[]; oidcSub?: string; + enabledApis?: string[]; } ): Promise { const userInfo: Record = {}; @@ -448,6 +456,15 @@ export abstract class BaseRedisStorage implements IStorage { } } + if (updates.enabledApis !== undefined) { + if (updates.enabledApis.length > 0) { + userInfo.enabledApis = JSON.stringify(updates.enabledApis); + } else { + // 删除enabledApis字段 + await this.withRetry(() => this.client.hDel(this.userInfoKey(userName), 'enabledApis')); + } + } + if (updates.oidcSub !== undefined) { const oldInfo = await this.getUserInfoV2(userName); if (oldInfo?.oidcSub && oldInfo.oidcSub !== updates.oidcSub) { @@ -499,6 +516,8 @@ export abstract class BaseRedisStorage implements IStorage { role: 'owner' | 'admin' | 'user'; banned: boolean; tags?: string[]; + oidcSub?: string; + enabledApis?: string[]; created_at: number; }>; total: number;