mirror of
https://github.com/router-for-me/Cli-Proxy-API-Management-Center.git
synced 2026-02-20 03:30:50 +08:00
refactor(core): harden API parsing and improve type safety
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user