mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-08-04 19:45:34 +08:00
fix(codex): fix config.toml not updated after extracting common config
The handleExtract function assumed codexConfig was JSON format, but it's actually a pure TOML string from useCodexConfigState. JSON.parse() failed silently, causing onConfigChange not to be called. Changes: - Handle both pure TOML string and legacy JSON format - Add missing i18n key for zh.json
This commit is contained in:
@@ -406,23 +406,34 @@ export function useCodexCommonConfig({
|
|||||||
const customToml = extractConfigToml(codexConfig);
|
const customToml = extractConfigToml(codexConfig);
|
||||||
const diffResult = extractTomlDifference(customToml, extracted);
|
const diffResult = extractTomlDifference(customToml, extracted);
|
||||||
if (!diffResult.error) {
|
if (!diffResult.error) {
|
||||||
// 更新 codexConfig 中的 config 字段
|
// 更新 codexConfig
|
||||||
|
// codexConfig 可能是两种格式:
|
||||||
|
// 1. 纯 TOML 字符串(来自 useCodexConfigState)
|
||||||
|
// 2. JSON 字符串 { auth: {...}, config: "..." }(旧格式)
|
||||||
|
let updated = false;
|
||||||
try {
|
try {
|
||||||
const parsed = JSON.parse(codexConfig);
|
const parsed = JSON.parse(codexConfig);
|
||||||
parsed.config = diffResult.customToml;
|
if (typeof parsed?.config === "string") {
|
||||||
onConfigChange(JSON.stringify(parsed, null, 2));
|
// JSON 格式,更新 config 字段
|
||||||
// Notify user that config was modified (提示用户需要保存)
|
parsed.config = diffResult.customToml;
|
||||||
toast.success(
|
onConfigChange(JSON.stringify(parsed, null, 2));
|
||||||
t("codexConfig.extractSuccessNeedSave", {
|
updated = true;
|
||||||
defaultValue: "已提取通用配置,点击保存按钮完成保存",
|
}
|
||||||
}),
|
} catch {
|
||||||
);
|
// JSON 解析失败,说明是纯 TOML 字符串
|
||||||
} catch (parseError) {
|
|
||||||
console.warn(
|
|
||||||
"[Extract] Failed to update codexConfig after extract:",
|
|
||||||
parseError,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 如果是纯 TOML 字符串,直接更新
|
||||||
|
if (!updated) {
|
||||||
|
onConfigChange(diffResult.customToml);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Notify user that config was modified (提示用户需要保存)
|
||||||
|
toast.success(
|
||||||
|
t("codexConfig.extractSuccessNeedSave", {
|
||||||
|
defaultValue: "已提取通用配置,点击保存按钮完成保存",
|
||||||
|
}),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("提取 Codex 通用配置失败:", error);
|
console.error("提取 Codex 通用配置失败:", error);
|
||||||
|
|||||||
@@ -565,6 +565,7 @@
|
|||||||
"extractFromCurrent": "从编辑内容提取",
|
"extractFromCurrent": "从编辑内容提取",
|
||||||
"extractNoCommonConfig": "当前编辑内容没有可提取的通用配置",
|
"extractNoCommonConfig": "当前编辑内容没有可提取的通用配置",
|
||||||
"extractFailed": "提取失败: {{error}}",
|
"extractFailed": "提取失败: {{error}}",
|
||||||
|
"extractSuccessNeedSave": "已提取通用配置,点击保存按钮完成保存",
|
||||||
"saveFailed": "保存失败: {{error}}"
|
"saveFailed": "保存失败: {{error}}"
|
||||||
},
|
},
|
||||||
"geminiConfig": {
|
"geminiConfig": {
|
||||||
|
|||||||
Reference in New Issue
Block a user