mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-06-16 13:34:04 +08:00
feat(backend): add unified deeplink import command
Add a new unified command handler for importing all resource types
via deeplinks, replacing the legacy provider-only import command.
Changes:
- Add import_from_deeplink_unified command supporting all resource types
- Keep import_from_deeplink for backward compatibility (now marked legacy)
- Route imports based on request.resource field (provider/prompt/mcp/skill)
- Return typed ImportResult with resource-specific data
Return types:
- Provider: { type: "provider", id: string }
- Prompt: { type: "prompt", id: string }
- MCP: { type: "mcp", importedCount, importedIds, failed }
- Skill: { type: "skill", key: string }
The unified handler simplifies frontend logic by providing consistent
return types and error handling across all resource types.
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
use crate::deeplink::{import_provider_from_deeplink, parse_deeplink_url, DeepLinkImportRequest};
|
||||
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;
|
||||
|
||||
@@ -15,18 +18,18 @@ pub fn parse_deeplink(url: String) -> Result<DeepLinkImportRequest, String> {
|
||||
pub fn merge_deeplink_config(
|
||||
request: DeepLinkImportRequest,
|
||||
) -> Result<DeepLinkImportRequest, String> {
|
||||
log::info!("Merging config for deep link request: {}", request.name);
|
||||
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 (after user confirmation)
|
||||
/// 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 {}",
|
||||
"Importing provider from deep link: {:?} for app {:?}",
|
||||
request.name,
|
||||
request.app
|
||||
);
|
||||
@@ -37,3 +40,50 @@ pub fn import_from_deeplink(
|
||||
|
||||
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)),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user