fix: update desktop links and skills market

This commit is contained in:
boos
2026-06-29 11:43:49 +08:00
parent 6863ccd16c
commit 8c9fbea822
3 changed files with 35 additions and 8 deletions
+30 -4
View File
@@ -633,6 +633,10 @@ pub async fn search_marketplace(
Ok(results)
}
_ => {
if query.chars().count() < 2 {
return Ok(builtin_results);
}
let url = format!(
"https://skills.sh/api/search?q={}",
urlencoding::encode(query)
@@ -651,24 +655,46 @@ pub async fn search_marketplace(
}
let body: serde_json::Value = response.json().await.map_err(|e| e.to_string())?;
let items = body["skills"].as_array().cloned().unwrap_or_default();
let items = body
.get("skills")
.or_else(|| body.get("results"))
.or_else(|| body.get("items"))
.and_then(|value| value.as_array())
.cloned()
.unwrap_or_default();
let mut results: Vec<MarketplaceSkill> = items
.into_iter()
.map(|item| {
let skill_name = item["name"].as_str().unwrap_or("").to_string();
let repo = item["source"].as_str().unwrap_or("").to_string();
let skill_name = item
.get("name")
.or_else(|| item.get("skillId"))
.and_then(|value| value.as_str())
.unwrap_or("")
.to_string();
let repo = item
.get("source")
.or_else(|| item.get("repo"))
.or_else(|| item.get("repository"))
.and_then(|value| value.as_str())
.unwrap_or("")
.trim()
.trim_start_matches("https://github.com/")
.trim_end_matches(".git")
.trim_end_matches('/')
.to_string();
let installed =
installed_refs.contains(&repo.trim().trim_end_matches('/').to_lowercase());
MarketplaceSkill {
name: skill_name,
description: String::new(),
description: item["description"].as_str().unwrap_or("").to_string(),
repo,
stars: 0,
installs: item["installs"].as_i64().unwrap_or(0),
installed,
}
})
.filter(|item| !item.repo.trim().is_empty())
.collect();
merge_marketplace_results(&mut results, builtin_results);