fix: update desktop links and skills market
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user