Fix catalog refresh: handle null fields in AppImageHub feed JSON

The AppImageHub feed.json contains null values where arrays/strings are
expected (296 items with null links, 6 items with null inside categories
arrays). Changed AppImageHubItem deserialization to use Option types and
flatten nulls. Also fixed refresh handler to dynamically look up the
catalog source from DB instead of hardcoding id.
This commit is contained in:
lashman
2026-02-28 00:46:39 +02:00
parent 31da61f3da
commit 582344ad48
2 changed files with 14 additions and 15 deletions

View File

@@ -152,17 +152,17 @@ fn fetch_appimage_hub() -> Result<Vec<CatalogApp>, CatalogError> {
let apps: Vec<CatalogApp> = feed.items.into_iter().filter_map(|item| {
// AppImageHub items need at least a name and a link
let name = item.name?;
let download_url = item.links.into_iter()
let download_url = item.links.unwrap_or_default().into_iter()
.find(|l| l.r#type == "Download")
.map(|l| l.url)?;
Some(CatalogApp {
name,
description: item.description,
categories: item.categories.unwrap_or_default(),
categories: item.categories.unwrap_or_default().into_iter().flatten().collect(),
latest_version: None,
download_url,
icon_url: item.icons.and_then(|icons| icons.into_iter().next()),
icon_url: item.icons.and_then(|icons| icons.into_iter().flatten().next()),
homepage: item.authors.and_then(|a| {
let first = a.into_iter().next()?;
if let Some(ref author_name) = first.name {
@@ -237,10 +237,10 @@ struct AppImageHubFeed {
struct AppImageHubItem {
name: Option<String>,
description: Option<String>,
categories: Option<Vec<String>>,
categories: Option<Vec<Option<String>>>,
authors: Option<Vec<AppImageHubAuthor>>,
links: Vec<AppImageHubLink>,
icons: Option<Vec<String>>,
links: Option<Vec<AppImageHubLink>>,
icons: Option<Vec<Option<String>>>,
}
#[derive(Debug, serde::Deserialize)]

View File

@@ -175,15 +175,14 @@ pub fn build_catalog_page(db: &Rc<Database>) -> adw::NavigationPage {
let db_bg = Database::open().ok();
let result = gio::spawn_blocking(move || {
if let Some(ref db) = db_bg {
catalog::sync_catalog(db, &catalog::CatalogSource {
id: Some(1),
name: "AppImageHub".to_string(),
url: "https://appimage.github.io/feed.json".to_string(),
source_type: catalog::CatalogType::AppImageHub,
enabled: true,
last_synced: None,
app_count: 0,
}).map_err(|e| e.to_string())
catalog::ensure_default_sources(db);
let sources = catalog::get_sources(db);
if let Some(source) = sources.first() {
catalog::sync_catalog(db, source)
.map_err(|e| e.to_string())
} else {
Err("No catalog sources configured".to_string())
}
} else {
Err("Failed to open database".to_string())
}