mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-29 01:25:33 +08:00
refactor(codex): unify custom model_provider routing key to "custom"
- Always emit `model_provider = "custom"` from deep link, UniversalProvider, and the universal form modal so future writes share one stable routing key. - Add `codex_provider_template_v1` local migration that rewrites legacy keys (aihubmix/ccswitch/...) under `[model_providers.custom]`, updates profile refs, and backs up the original settings_config under `~/.cc-switch/backups/<timestamp>/providers/`. - Tighten history migration source detection to a whitelist plus `[model_providers.<id>]` existence check so user-authored keys are never rewritten in jsonl/state DB. - Encode deep link name/model/endpoint through `toml_edit::Value` so display names containing quotes or backslashes no longer break the generated config.toml. - Stabilize provider settings backup filename hash with Sha256 (was process-random SipHash).
This commit is contained in:
@@ -178,13 +178,15 @@ impl WebDavSyncSettings {
|
||||
|
||||
/// 本机自动迁移状态。
|
||||
///
|
||||
/// 这里记录的是设备级操作(例如修改本机 `~/.codex` 文件),不随数据库同步。
|
||||
/// 这里记录的是本机启动时执行过的一次性迁移;标记不随数据库同步。
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct LocalMigrations {
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub codex_third_party_history_provider_bucket_v1:
|
||||
Option<CodexThirdPartyHistoryProviderBucketMigration>,
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub codex_provider_template_v1: Option<CodexProviderTemplateMigration>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
@@ -202,6 +204,14 @@ pub struct CodexThirdPartyHistoryProviderBucketMigration {
|
||||
pub scanned_history_files: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct CodexProviderTemplateMigration {
|
||||
pub completed_at: String,
|
||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||
pub migrated_provider_ids: Vec<String>,
|
||||
}
|
||||
|
||||
/// 应用设置结构
|
||||
///
|
||||
/// 存储设备级别设置,保存在本地 `~/.cc-switch/settings.json`,不随数据库同步。
|
||||
@@ -610,6 +620,25 @@ pub fn mark_codex_third_party_history_provider_bucket_migrated(
|
||||
})
|
||||
}
|
||||
|
||||
pub fn is_codex_provider_template_migrated() -> bool {
|
||||
get_settings()
|
||||
.local_migrations
|
||||
.as_ref()
|
||||
.and_then(|migrations| migrations.codex_provider_template_v1.as_ref())
|
||||
.is_some()
|
||||
}
|
||||
|
||||
pub fn mark_codex_provider_template_migrated(
|
||||
migration: CodexProviderTemplateMigration,
|
||||
) -> Result<(), AppError> {
|
||||
mutate_settings(|settings| {
|
||||
let migrations = settings
|
||||
.local_migrations
|
||||
.get_or_insert_with(Default::default);
|
||||
migrations.codex_provider_template_v1 = Some(migration);
|
||||
})
|
||||
}
|
||||
|
||||
/// 从文件重新加载设置到内存缓存
|
||||
/// 用于导入配置等场景,确保内存缓存与文件同步
|
||||
pub fn reload_settings() -> Result<(), AppError> {
|
||||
|
||||
Reference in New Issue
Block a user