修复迁移丢失enabledApis字段

This commit is contained in:
mtvpls
2025-12-25 00:39:30 +08:00
parent 2e545466cb
commit 35fc89b33e

View File

@@ -342,7 +342,8 @@ export abstract class BaseRedisStorage implements IStorage {
password: string, password: string,
role: 'owner' | 'admin' | 'user' = 'user', role: 'owner' | 'admin' | 'user' = 'user',
tags?: string[], tags?: string[],
oidcSub?: string oidcSub?: string,
enabledApis?: string[]
): Promise<void> { ): Promise<void> {
const hashedPassword = await this.hashPassword(password); const hashedPassword = await this.hashPassword(password);
const createdAt = Date.now(); const createdAt = Date.now();
@@ -359,6 +360,10 @@ export abstract class BaseRedisStorage implements IStorage {
userInfo.tags = JSON.stringify(tags); userInfo.tags = JSON.stringify(tags);
} }
if (enabledApis && enabledApis.length > 0) {
userInfo.enabledApis = JSON.stringify(enabledApis);
}
if (oidcSub) { if (oidcSub) {
userInfo.oidcSub = oidcSub; userInfo.oidcSub = oidcSub;
// 创建OIDC映射 // 创建OIDC映射
@@ -400,6 +405,7 @@ export abstract class BaseRedisStorage implements IStorage {
banned: boolean; banned: boolean;
tags?: string[]; tags?: string[];
oidcSub?: string; oidcSub?: string;
enabledApis?: string[];
created_at: number; created_at: number;
} | null> { } | null> {
const userInfo = await this.withRetry(() => const userInfo = await this.withRetry(() =>
@@ -415,6 +421,7 @@ export abstract class BaseRedisStorage implements IStorage {
banned: userInfo.banned === 'true', banned: userInfo.banned === 'true',
tags: userInfo.tags ? JSON.parse(userInfo.tags) : undefined, tags: userInfo.tags ? JSON.parse(userInfo.tags) : undefined,
oidcSub: userInfo.oidcSub, oidcSub: userInfo.oidcSub,
enabledApis: userInfo.enabledApis ? JSON.parse(userInfo.enabledApis) : undefined,
created_at: parseInt(userInfo.created_at || '0', 10), created_at: parseInt(userInfo.created_at || '0', 10),
}; };
} }
@@ -427,6 +434,7 @@ export abstract class BaseRedisStorage implements IStorage {
banned?: boolean; banned?: boolean;
tags?: string[]; tags?: string[];
oidcSub?: string; oidcSub?: string;
enabledApis?: string[];
} }
): Promise<void> { ): Promise<void> {
const userInfo: Record<string, string> = {}; const userInfo: Record<string, string> = {};
@@ -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) { if (updates.oidcSub !== undefined) {
const oldInfo = await this.getUserInfoV2(userName); const oldInfo = await this.getUserInfoV2(userName);
if (oldInfo?.oidcSub && oldInfo.oidcSub !== updates.oidcSub) { if (oldInfo?.oidcSub && oldInfo.oidcSub !== updates.oidcSub) {
@@ -499,6 +516,8 @@ export abstract class BaseRedisStorage implements IStorage {
role: 'owner' | 'admin' | 'user'; role: 'owner' | 'admin' | 'user';
banned: boolean; banned: boolean;
tags?: string[]; tags?: string[];
oidcSub?: string;
enabledApis?: string[];
created_at: number; created_at: number;
}>; }>;
total: number; total: number;