mirror of
https://github.com/router-for-me/Cli-Proxy-API-Management-Center.git
synced 2026-06-16 21:03:58 +08:00
refactor(providers): simplify section and array payload extraction
Backend list endpoints (config_lists.go: GetGeminiKeys / GetClaudeKeys /
GetCodexKeys / GetOpenAICompat / GetVertexCompatKeys) always wrap the
result as {"<kebab-section>": [...]}, never as a raw array, never under
"items" or "data". And /config emits the same kebab keys, so the camelCase
aliases (geminiApiKey, openAICompatibility, ...) are unreachable.
Remove RAW_SECTION_ALIASES and inline the lookup; drop the raw-array
and items/data fallbacks from extractArrayPayload.
This commit is contained in:
@@ -60,14 +60,6 @@ const API_KEY_ENTRY_FIELDS = ['api-key', 'proxy-url'] as const;
|
||||
|
||||
const CLOAK_FIELDS = ['mode', 'strict-mode', 'sensitive-words'] as const;
|
||||
|
||||
const RAW_SECTION_ALIASES: Record<string, readonly string[]> = {
|
||||
'gemini-api-key': ['gemini-api-key', 'geminiApiKey', 'geminiApiKeys'],
|
||||
'codex-api-key': ['codex-api-key', 'codexApiKey', 'codexApiKeys'],
|
||||
'claude-api-key': ['claude-api-key', 'claudeApiKey', 'claudeApiKeys'],
|
||||
'vertex-api-key': ['vertex-api-key', 'vertexApiKey', 'vertexApiKeys'],
|
||||
'openai-compatibility': ['openai-compatibility', 'openaiCompatibility', 'openAICompatibility'],
|
||||
};
|
||||
|
||||
const getStringField = (record: Record<string, unknown>, keys: readonly string[]) => {
|
||||
for (const key of keys) {
|
||||
const value = record[key];
|
||||
@@ -163,14 +155,10 @@ const mergeKnownRecordList = (
|
||||
});
|
||||
};
|
||||
|
||||
const getRawSectionList = (rawConfig: unknown, section: string) => {
|
||||
const getRawSectionList = (rawConfig: unknown, section: string): unknown[] => {
|
||||
if (!isRecord(rawConfig)) return [];
|
||||
const aliases = RAW_SECTION_ALIASES[section] ?? [section];
|
||||
for (const alias of aliases) {
|
||||
const value = rawConfig[alias];
|
||||
if (Array.isArray(value)) return value;
|
||||
}
|
||||
return [];
|
||||
const value = rawConfig[section];
|
||||
return Array.isArray(value) ? value : [];
|
||||
};
|
||||
|
||||
const mergeModelPayloads = (raw: unknown, models: unknown) =>
|
||||
@@ -242,10 +230,9 @@ const buildPreservedList = async <T>(
|
||||
};
|
||||
|
||||
const extractArrayPayload = (data: unknown, key: string): unknown[] => {
|
||||
if (Array.isArray(data)) return data;
|
||||
if (!isRecord(data)) return [];
|
||||
const candidate = data[key] ?? data.items ?? data.data ?? data;
|
||||
return Array.isArray(candidate) ? candidate : [];
|
||||
const list = data[key];
|
||||
return Array.isArray(list) ? list : [];
|
||||
};
|
||||
|
||||
const buildProviderDeleteQuery = (apiKey: string, baseUrl?: string) => {
|
||||
|
||||
Reference in New Issue
Block a user