forked from boos/BoosAPI
Merge pull request #214 from zmoon460/main
Fix: postgres 环境下无法保存 模型白名单和群组选择
This commit is contained in:
@@ -22,6 +22,10 @@ function validateKeyShape(key: string): boolean {
|
|||||||
|
|
||||||
function looksLikeUniqueViolation(error: unknown): boolean {
|
function looksLikeUniqueViolation(error: unknown): boolean {
|
||||||
const message = (error as Error | undefined)?.message || '';
|
const message = (error as Error | undefined)?.message || '';
|
||||||
|
if (runtimeDbDialect === 'postgres') {
|
||||||
|
return message.includes('duplicate key value violates unique constraint') &&
|
||||||
|
message.includes('downstream_api_keys_key_unique');
|
||||||
|
}
|
||||||
return message.includes('UNIQUE constraint failed') && message.includes('downstream_api_keys.key');
|
return message.includes('UNIQUE constraint failed') && message.includes('downstream_api_keys.key');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -90,13 +90,25 @@ function normalizePositiveIntegerOrNull(value: unknown): number | null {
|
|||||||
return normalized;
|
return normalized;
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseJson(value: string | null | undefined): unknown {
|
function parseJson(value: unknown): unknown {
|
||||||
if (!value) return null;
|
if (value === null || value === undefined) return null;
|
||||||
try {
|
|
||||||
return JSON.parse(value);
|
// PostgreSQL JSONB columns are returned as parsed objects/arrays by the pg driver
|
||||||
} catch {
|
if (typeof value === 'object') {
|
||||||
return null;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SQLite TEXT columns store JSON as strings that need parsing
|
||||||
|
if (typeof value === 'string') {
|
||||||
|
if (value === '') return null;
|
||||||
|
try {
|
||||||
|
return JSON.parse(value);
|
||||||
|
} catch {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function normalizeGroupNameInput(input: unknown): string | null {
|
export function normalizeGroupNameInput(input: unknown): string | null {
|
||||||
|
|||||||
Reference in New Issue
Block a user