mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-08-03 19:12:04 +08:00
22d2872c33
Backend half of the logging overhaul. Retention: - Keep the last 4 rotated files at 20MB each and stop deleting logs on startup, so a crash's prior-run logs survive a restart. - Apply the persisted log level right after plugin registration instead of at the end of setup. - Bound crash.log with size-based rotation (5MB x 2). Secret redaction on every log path: - Proxy: strip userinfo/query from upstream URLs (keep path for diagnostics), exact-match redact known auth.api_key/access_token, classify request/response bodies instead of logging them, header allowlist. - Redact the Gemini `?key=` in cache-trace endpoints. - Omit MCP custom-field values (headers may carry tokens). - Redact deeplink and model-fetch URLs before logging. Docs: - FAQ points users to the persistent crash.log for support workflows.
90 lines
3.1 KiB
Rust
90 lines
3.1 KiB
Rust
use crate::deeplink::{
|
|
import_mcp_from_deeplink, import_prompt_from_deeplink, import_provider_from_deeplink,
|
|
import_skill_from_deeplink, parse_deeplink_url, DeepLinkImportRequest,
|
|
};
|
|
use crate::store::AppState;
|
|
use tauri::State;
|
|
|
|
/// Parse a deep link URL and return the parsed request for frontend confirmation
|
|
#[tauri::command]
|
|
pub fn parse_deeplink(url: String) -> Result<DeepLinkImportRequest, String> {
|
|
log::info!("Parsing deep link URL: {}", crate::url_for_log(&url));
|
|
parse_deeplink_url(&url).map_err(|e| e.to_string())
|
|
}
|
|
|
|
/// Merge configuration from Base64/URL into a deep link request
|
|
/// This is used by the frontend to show the complete configuration in the confirmation dialog
|
|
#[tauri::command]
|
|
pub fn merge_deeplink_config(
|
|
request: DeepLinkImportRequest,
|
|
) -> Result<DeepLinkImportRequest, String> {
|
|
log::info!("Merging config for deep link request: {:?}", request.name);
|
|
crate::deeplink::parse_and_merge_config(&request).map_err(|e| e.to_string())
|
|
}
|
|
|
|
/// Import a provider from a deep link request (legacy, kept for compatibility)
|
|
#[tauri::command]
|
|
pub fn import_from_deeplink(
|
|
state: State<AppState>,
|
|
request: DeepLinkImportRequest,
|
|
) -> Result<String, String> {
|
|
log::info!(
|
|
"Importing provider from deep link: {:?} for app {:?}",
|
|
request.name,
|
|
request.app
|
|
);
|
|
|
|
let provider_id = import_provider_from_deeplink(&state, request).map_err(|e| e.to_string())?;
|
|
|
|
log::info!("Successfully imported provider with ID: {provider_id}");
|
|
|
|
Ok(provider_id)
|
|
}
|
|
|
|
/// Import resource from a deep link request (unified handler)
|
|
#[tauri::command]
|
|
pub async fn import_from_deeplink_unified(
|
|
state: State<'_, AppState>,
|
|
request: DeepLinkImportRequest,
|
|
) -> Result<serde_json::Value, String> {
|
|
log::info!("Importing {} resource from deep link", request.resource);
|
|
|
|
match request.resource.as_str() {
|
|
"provider" => {
|
|
let provider_id =
|
|
import_provider_from_deeplink(&state, request).map_err(|e| e.to_string())?;
|
|
Ok(serde_json::json!({
|
|
"type": "provider",
|
|
"id": provider_id
|
|
}))
|
|
}
|
|
"prompt" => {
|
|
let prompt_id =
|
|
import_prompt_from_deeplink(&state, request).map_err(|e| e.to_string())?;
|
|
Ok(serde_json::json!({
|
|
"type": "prompt",
|
|
"id": prompt_id
|
|
}))
|
|
}
|
|
"mcp" => {
|
|
let result = import_mcp_from_deeplink(&state, request).map_err(|e| e.to_string())?;
|
|
// Add type field to the result
|
|
Ok(serde_json::json!({
|
|
"type": "mcp",
|
|
"importedCount": result.imported_count,
|
|
"importedIds": result.imported_ids,
|
|
"failed": result.failed
|
|
}))
|
|
}
|
|
"skill" => {
|
|
let skill_key =
|
|
import_skill_from_deeplink(&state, request).map_err(|e| e.to_string())?;
|
|
Ok(serde_json::json!({
|
|
"type": "skill",
|
|
"key": skill_key
|
|
}))
|
|
}
|
|
_ => Err(format!("Unsupported resource type: {}", request.resource)),
|
|
}
|
|
}
|