← Commit history

v0.3.1 discovery fix

John Lauer ·a32549d477 ·4mo ago ·parent 564106c
1 file changed +8−4
src/plugins.rs+8−4
@@ -128,9 +128,13 @@ pub fn discover_installed() -> Vec<Plugin> { }  /// Best-effort registry query for publishable (not-yet-installed) plugins.+///+/// The wiki's `/discover?triggers=` endpoint is unreliable for hyphenated tags,+/// so we use full-text search (`?q=adom-usb`) and keep the `adom-usb-*` family+/// (the plugin naming convention) minus the app itself and anything installed. pub fn discover_registry(installed: &[Plugin]) -> Vec<Plugin> {-    let url = format!("https://wiki.adom.inc/api/v1/discover?triggers={}", PLUGIN_TAG);-    let resp = match ureq::get(&url)+    let url = "https://wiki.adom.inc/api/v1/search?q=adom-usb";+    let resp = match ureq::get(url)         .timeout(std::time::Duration::from_millis(2500))         .set("User-Agent", "adom-usb/plugin-discovery")         .call()@@ -140,11 +144,11 @@ pub fn discover_registry(installed: &[Plugin]) -> Vec<Plugin> {     };     let v: Value = match resp.into_json() { Ok(v) => v, Err(_) => return Vec::new() };     let arr = if v.is_array() { v.as_array().cloned().unwrap_or_default() }-        else { v.get("results").or_else(|| v.get("packages")).and_then(|x| x.as_array()).cloned().unwrap_or_default() };+        else { v.get("results").or_else(|| v.get("pages")).or_else(|| v.get("packages")).and_then(|x| x.as_array()).cloned().unwrap_or_default() };     let have: std::collections::HashSet<&str> = installed.iter().map(|p| p.slug.as_str()).collect();     arr.iter().filter_map(|item| {         let slug = item.get("slug").and_then(|s| s.as_str())?;-        if have.contains(slug) || slug == "adom-usb" { return None; }+        if have.contains(slug) || slug == "adom-usb" || !slug.starts_with("adom-usb-") { return None; }         Some(Plugin {             slug: slug.to_string(),             name: item.get("title").and_then(|s| s.as_str()).unwrap_or(slug).to_string(),