mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-25 13:45:03 +08:00
0f959112b1
Remove the skillsPath field from SkillRepo and Skill structs since recursive scanning now automatically discovers skills in all directories. Simplify the UI by removing the path input field.
52 lines
1.5 KiB
Rust
52 lines
1.5 KiB
Rust
//! Skill import from deep link
|
|
//!
|
|
//! Handles importing skill repository configurations via ccswitch:// URLs.
|
|
|
|
use super::DeepLinkImportRequest;
|
|
use crate::error::AppError;
|
|
use crate::services::skill::SkillRepo;
|
|
use crate::store::AppState;
|
|
|
|
/// Import a skill from deep link request
|
|
pub fn import_skill_from_deeplink(
|
|
state: &AppState,
|
|
request: DeepLinkImportRequest,
|
|
) -> Result<String, AppError> {
|
|
// Verify this is a skill request
|
|
if request.resource != "skill" {
|
|
return Err(AppError::InvalidInput(format!(
|
|
"Expected skill resource, got '{}'",
|
|
request.resource
|
|
)));
|
|
}
|
|
|
|
// Parse repo
|
|
let repo_str = request
|
|
.repo
|
|
.ok_or_else(|| AppError::InvalidInput("Missing 'repo' field for skill".to_string()))?;
|
|
|
|
let parts: Vec<&str> = repo_str.split('/').collect();
|
|
if parts.len() != 2 {
|
|
return Err(AppError::InvalidInput(format!(
|
|
"Invalid repo format: expected 'owner/name', got '{repo_str}'"
|
|
)));
|
|
}
|
|
let owner = parts[0].to_string();
|
|
let name = parts[1].to_string();
|
|
|
|
// Create SkillRepo
|
|
let repo = SkillRepo {
|
|
owner: owner.clone(),
|
|
name: name.clone(),
|
|
branch: request.branch.unwrap_or_else(|| "main".to_string()),
|
|
enabled: request.enabled.unwrap_or(true),
|
|
};
|
|
|
|
// Save using Database
|
|
state.db.save_skill_repo(&repo)?;
|
|
|
|
log::info!("Successfully added skill repo '{owner}/{name}'");
|
|
|
|
Ok(format!("{owner}/{name}"))
|
|
}
|