Add source URL tracking and display for AppImages

This commit is contained in:
lashman
2026-02-27 23:40:18 +02:00
parent f5685e03e3
commit 78f004ff4f
4 changed files with 41 additions and 2 deletions

View File

@@ -1744,6 +1744,16 @@ impl Database {
Ok(self.conn.last_insert_rowid())
}
// --- Source URL ---
pub fn set_source_url(&self, id: i64, url: Option<&str>) -> SqlResult<()> {
self.conn.execute(
"UPDATE appimages SET source_url = ?2 WHERE id = ?1",
params![id, url],
)?;
Ok(())
}
// --- Version rollback ---
pub fn set_previous_version(&self, id: i64, path: Option<&str>) -> SqlResult<()> {

View File

@@ -62,6 +62,29 @@ pub struct UpdateCheckResult {
pub file_size: Option<u64>,
}
/// Detect the source URL for an AppImage from its update_info string.
pub fn detect_source_url(update_info: Option<&str>) -> Option<String> {
let info = update_info?;
let parts: Vec<&str> = info.split('|').collect();
if info.starts_with("gh-releases-zsync|") && parts.len() >= 3 {
return Some(format!("https://github.com/{}/{}", parts[1], parts[2]));
}
if info.starts_with("gl-releases-zsync|") && parts.len() >= 4 {
return Some(format!("https://{}/{}/{}", parts[1], parts[2], parts[3]));
}
if info.starts_with("zsync|") {
if let Some(url_part) = parts.get(1) {
// Extract the base URL (up to the hostname)
if let Some(idx) = url_part.find("://") {
if let Some(slash) = url_part[idx + 3..].find('/') {
return Some(url_part[..idx + 3 + slash].to_string());
}
}
}
}
None
}
/// Parse the raw update info string from an AppImage's ELF section.
pub fn parse_update_info(raw: &str) -> Option<UpdateType> {
let raw = raw.trim().trim_matches('\0');