mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-25 13:45:03 +08:00
feat: restore Claude provider auth field selector (AUTH_TOKEN / API_KEY)
This commit is contained in:
@@ -295,9 +295,13 @@ export const hasApiKeyField = (
|
||||
export const setApiKeyInConfig = (
|
||||
jsonString: string,
|
||||
apiKey: string,
|
||||
options: { createIfMissing?: boolean; appType?: string } = {},
|
||||
options: {
|
||||
createIfMissing?: boolean;
|
||||
appType?: string;
|
||||
apiKeyField?: string;
|
||||
} = {},
|
||||
): string => {
|
||||
const { createIfMissing = false, appType } = options;
|
||||
const { createIfMissing = false, appType, apiKeyField } = options;
|
||||
try {
|
||||
const config = JSON.parse(jsonString);
|
||||
|
||||
@@ -337,13 +341,13 @@ export const setApiKeyInConfig = (
|
||||
return JSON.stringify(config, null, 2);
|
||||
}
|
||||
|
||||
// Claude API Key (优先写入已存在的字段;若两者均不存在且允许创建,则默认创建 AUTH_TOKEN 字段)
|
||||
// Claude API Key (优先写入已存在的字段;若两者均不存在且允许创建,则使用 apiKeyField 或默认 AUTH_TOKEN 字段)
|
||||
if ("ANTHROPIC_AUTH_TOKEN" in env) {
|
||||
env.ANTHROPIC_AUTH_TOKEN = apiKey;
|
||||
} else if ("ANTHROPIC_API_KEY" in env) {
|
||||
env.ANTHROPIC_API_KEY = apiKey;
|
||||
} else if (createIfMissing) {
|
||||
env.ANTHROPIC_AUTH_TOKEN = apiKey;
|
||||
env[apiKeyField ?? "ANTHROPIC_AUTH_TOKEN"] = apiKey;
|
||||
} else {
|
||||
return jsonString;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user