mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-04-03 02:28:09 +08:00
fix(usage): correct selectedTemplate initialization logic
Previously, selectedTemplate was initialized to null when no NEW_API credentials were detected, which caused the credentials config section to be hidden even for new configurations or GENERAL template users. Now properly detects: - NEW_API template (has accessToken or userId) - GENERAL template (has apiKey or baseUrl) - Default to GENERAL for new configurations (matches default code template)
This commit is contained in:
@@ -176,10 +176,16 @@ const UsageScriptModal: React.FC<UsageScriptModalProps> = ({
|
||||
const [selectedTemplate, setSelectedTemplate] = useState<string | null>(
|
||||
() => {
|
||||
const existingScript = provider.meta?.usage_script;
|
||||
// 检测 NEW_API 模板(有 accessToken 或 userId)
|
||||
if (existingScript?.accessToken || existingScript?.userId) {
|
||||
return TEMPLATE_KEYS.NEW_API;
|
||||
}
|
||||
return null;
|
||||
// 检测 GENERAL 模板(有 apiKey 或 baseUrl)
|
||||
if (existingScript?.apiKey || existingScript?.baseUrl) {
|
||||
return TEMPLATE_KEYS.GENERAL;
|
||||
}
|
||||
// 新配置或无凭证:默认使用 GENERAL(与默认代码模板一致)
|
||||
return TEMPLATE_KEYS.GENERAL;
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user