mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-24 12:44:18 +08:00
fix:Add a new vendor page, API endpoint, and model name. (#1155)
* fix:Add a new vendor page, API endpoint, and model name. Fix the bug where, after entering characters, line breaks cannot be fully deleted. * fix: add missing i18n key codexConfig.modelNameHint for zh/en/ja --------- Co-authored-by: Jason <farion1231@gmail.com>
This commit is contained in:
@@ -447,12 +447,23 @@ export const setCodexBaseUrl = (
|
||||
baseUrl: string,
|
||||
): string => {
|
||||
const trimmed = baseUrl.trim();
|
||||
if (!trimmed) {
|
||||
return configText;
|
||||
}
|
||||
// 归一化原文本中的引号(既能匹配,也能输出稳定格式)
|
||||
const normalizedText = normalizeQuotes(configText);
|
||||
|
||||
// 允许清空:当 baseUrl 为空时,移除 base_url 行
|
||||
if (!trimmed) {
|
||||
if (!normalizedText) return normalizedText;
|
||||
const next = normalizedText
|
||||
.split("\n")
|
||||
.filter((line) => !/^\s*base_url\s*=/.test(line))
|
||||
.join("\n")
|
||||
// 避免移除后留下过多空行
|
||||
.replace(/\n{3,}/g, "\n\n")
|
||||
// 避免开头出现空行
|
||||
.replace(/^\n+/, "");
|
||||
return next;
|
||||
}
|
||||
|
||||
const normalizedUrl = trimmed.replace(/\s+/g, "");
|
||||
const replacementLine = `base_url = "${normalizedUrl}"`;
|
||||
const pattern = /base_url\s*=\s*(["'])([^"']+)\1/;
|
||||
@@ -494,13 +505,21 @@ export const setCodexModelName = (
|
||||
modelName: string,
|
||||
): string => {
|
||||
const trimmed = modelName.trim();
|
||||
if (!trimmed) {
|
||||
return configText;
|
||||
}
|
||||
|
||||
// 归一化原文本中的引号(既能匹配,也能输出稳定格式)
|
||||
const normalizedText = normalizeQuotes(configText);
|
||||
|
||||
// 允许清空:当 modelName 为空时,移除 model 行
|
||||
if (!trimmed) {
|
||||
if (!normalizedText) return normalizedText;
|
||||
const next = normalizedText
|
||||
.split("\n")
|
||||
.filter((line) => !/^\s*model\s*=/.test(line))
|
||||
.join("\n")
|
||||
.replace(/\n{3,}/g, "\n\n")
|
||||
.replace(/^\n+/, "");
|
||||
return next;
|
||||
}
|
||||
|
||||
const replacementLine = `model = "${trimmed}"`;
|
||||
const pattern = /^model\s*=\s*["']([^"']+)["']/m;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user