重构: 巨函数拆分 + 清理历史标记注释 + custom_prompt/停止按钮/tunnel 改进

This commit is contained in:
lxy
2026-07-31 21:36:12 +08:00
parent 365af554da
commit bd9031d35d
73 changed files with 1421 additions and 1064 deletions
+7 -7
View File
@@ -1,4 +1,4 @@
//! FR-S1 api_key 密钥管理 — 真实密钥存 OS keyring,DB `api_key` 列迁移后存空串。
//! api_key 密钥管理 — 真实密钥存 OS keyring,DB `api_key` 列迁移后存空串。
//!
//! **下沉层(方案 B,2026-06-16)**:原位于 `src-tauri/src/commands/ai/secret.rs`,
//! 下沉纯密钥逻辑(get/set/delete/resolve/ensure/migrate + failcount sidecar)到 df-storage,
@@ -67,7 +67,7 @@ fn write_failcounts(map: &HashMap<String, u32>) {
text.push('\n');
}
if let Err(e) = fs::write(failcount_path(), text) {
tracing::debug!("[FR-S1] 迁移失败计数文件写入失败(忽略): {}", e);
tracing::debug!("[密钥迁移] 迁移失败计数文件写入失败(忽略): {}", e);
}
}
@@ -172,14 +172,14 @@ pub async fn migrate_secrets_to_keyring(repo: &AiProviderRepo) -> anyhow::Result
let n = record_migration_fail(&p.id);
if n >= MIGRATION_FAIL_THRESHOLD {
tracing::warn!(
"[FR-S1] provider {} keyring 迁移已连续失败 {} 次,明文 api_key 长期滞留 SQLite 文件(无加密)。\
"[密钥迁移] provider {} keyring 迁移已连续失败 {} 次,明文 api_key 长期滞留 SQLite 文件(无加密)。\
建议:1) 确认 OS 钥匙串可用(Win Credential Manager / macOS Keychain);\
2) keyring 后端异常时排查对应平台后端;3) 必要时手动在设置中重新保存密钥触发写入",
p.id, n
);
} else {
tracing::warn!(
"[FR-S1] keyring 迁移失败 {} (累计 {}/{},保留明文下次重试): {}",
"[密钥迁移] keyring 迁移失败 {} (累计 {}/{},保留明文下次重试): {}",
p.id, n, MIGRATION_FAIL_THRESHOLD, e
);
}
@@ -188,14 +188,14 @@ pub async fn migrate_secrets_to_keyring(repo: &AiProviderRepo) -> anyhow::Result
let pid = p.id.clone();
p.api_key.clear();
if let Err(e) = repo.insert(p).await {
tracing::warn!("[FR-S1] 迁移后清空 DB api_key 失败 {}: {}", pid, e);
tracing::warn!("[密钥迁移] 迁移后清空 DB api_key 失败 {}: {}", pid, e);
}
// 迁移成功 → 清零该 provider 的失败计数(下次若再出现失败从 1 重新累计)
clear_migration_failcount(&pid);
migrated += 1;
}
if migrated > 0 {
tracing::info!("[FR-S1] {} 条 provider 密钥迁移至 OS keyring", migrated);
tracing::info!("[密钥迁移] {} 条 provider 密钥迁移至 OS keyring", migrated);
}
Ok(migrated)
}
@@ -241,7 +241,7 @@ mod tests {
#[test]
fn resolve_prefers_db_when_non_empty() {
// DB api_key 非空 → 直接返回 DB 值,不触发 keyring(FR-S1 兼容未迁移老库)
// DB api_key 非空 → 直接返回 DB 值,不触发 keyring(兼容未迁移老库)
// 纯逻辑路径,不碰 OS keyring,CI 任意 OS 安全。
let rec = AiProviderRecord {
id: "t1".into(), name: "t".into(), provider_type: "openai_compat".into(),