Add source URL tracking and display for AppImages
This commit is contained in:
@@ -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<()> {
|
||||
|
||||
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user