refactor(core): harden API parsing and improve type safety

This commit is contained in:
LTbinglingfeng
2026-02-08 09:42:00 +08:00
parent 3783bec983
commit 6c2cd761ba
39 changed files with 689 additions and 404 deletions

View File

@@ -62,14 +62,23 @@ export function DashboardPage() {
apiKeysCache.current = [];
}, [apiBase, config?.apiKeys]);
const normalizeApiKeyList = (input: any): string[] => {
const normalizeApiKeyList = (input: unknown): string[] => {
if (!Array.isArray(input)) return [];
const seen = new Set<string>();
const keys: string[] = [];
input.forEach((item) => {
const value = typeof item === 'string' ? item : item?.['api-key'] ?? item?.apiKey ?? '';
const trimmed = String(value || '').trim();
const record =
item !== null && typeof item === 'object' && !Array.isArray(item)
? (item as Record<string, unknown>)
: null;
const value =
typeof item === 'string'
? item
: record
? (record['api-key'] ?? record['apiKey'] ?? record.key ?? record.Key)
: '';
const trimmed = String(value ?? '').trim();
if (!trimmed || seen.has(trimmed)) return;
seen.add(trimmed);
keys.push(trimmed);