use serde::Deserialize;
#[derive(Debug, Clone, Deserialize)]
pub struct GithubReleaseAssetRecord {
pub name: String,
pub browser_download_url: String,
}
#[derive(Debug, Clone, Deserialize)]
pub struct GithubReleaseApiResponse {
pub tag_name: String,
#[serde(default)]
pub assets: Vec<GithubReleaseAssetRecord>,
}
pub fn rewrite_github_download_url(download_url: &str, github_base_url: Option<&str>) -> String {
let Some(base_url) = github_base_url
.map(str::trim)
.filter(|value| !value.is_empty())
else {
return download_url.to_string();
};
let normalized_base = base_url.trim_end_matches('/');
if download_url.starts_with("https://github.com/") {
format!(
"{}/{}",
normalized_base,
download_url.trim_start_matches("https://github.com/")
)
} else if download_url.starts_with("http://github.com/") {
format!(
"{}/{}",
normalized_base,
download_url.trim_start_matches("http://github.com/")
)
} else {
download_url.to_string()
}
}