重大重构:从字段替换切换到完整配置文件切换系统

- 实现基于文件重命名的供应商切换机制,支持完整settings.json配置切换
- 移除所有向后兼容代码,简化为纯JSON配置模式
- 添加导入当前配置功能,解决首次使用时配置丢失问题
- 移除描述字段,简化用户界面
- 完整的错误处理和回滚机制确保配置安全
- 清理所有调试代码,优化代码质量
This commit is contained in:
farion1231
2025-08-07 15:48:30 +08:00
parent e03848af56
commit c268f962af
12 changed files with 548 additions and 364 deletions
+4 -2
View File
@@ -1,9 +1,10 @@
export interface Provider {
id: string
name: string
apiUrl: string
apiKey: string
settingsConfig: object // 完整的Claude Code settings.json配置
websiteUrl?: string
createdAt?: number
updatedAt?: number
}
export interface AppConfig {
@@ -20,6 +21,7 @@ declare global {
deleteProvider: (id: string) => Promise<boolean>
updateProvider: (provider: Provider) => Promise<boolean>
switchProvider: (providerId: string) => Promise<boolean>
importCurrentConfig: (name: string) => Promise<{ success: boolean; providerId?: string }>
getClaudeCodeConfigPath: () => Promise<string>
selectConfigFile: () => Promise<string | null>
openExternal: (url: string) => Promise<boolean>
-42
View File
@@ -1,42 +0,0 @@
/**
* 从API地址推测对应的网站地址
* @param apiUrl API地址
* @returns 推测的网站地址,如果无法推测则返回空字符串
*/
export function inferWebsiteUrl(apiUrl: string): string {
if (!apiUrl || !apiUrl.trim()) {
return ''
}
let urlString = apiUrl.trim()
// 如果没有协议,默认添加 https://
if (!urlString.match(/^https?:\/\//)) {
urlString = 'https://' + urlString
}
try {
const url = new URL(urlString)
// 如果是localhost或IP地址,去掉路径部分
if (url.hostname === 'localhost' || /^\d+\.\d+\.\d+\.\d+$/.test(url.hostname)) {
return `${url.protocol}//${url.host}`
}
// 处理域名,去掉api前缀
let hostname = url.hostname
// 去掉 api. 前缀
if (hostname.startsWith('api.')) {
hostname = hostname.substring(4)
}
// 构建推测的网站地址
const port = url.port ? `:${url.port}` : ''
return `${url.protocol}//${hostname}${port}`
} catch (error) {
// URL解析失败,返回空字符串
return ''
}
}