app_store: allow frontend to select mirror to use via POST body

This commit is contained in:
dr-frmr 2024-02-10 19:17:23 -03:00
parent b4c44cc79f
commit acebc82a59
No known key found for this signature in database
2 changed files with 13 additions and 8 deletions

View File

@ -235,10 +235,12 @@ fn serve_paths(
}
Method::POST => {
// download an app
// TODO get fields from POST body
let pkg_listing: &PackageListing = state
.get_listing(&package_id)
.ok_or(anyhow::anyhow!("No package"))?;
// from POST body, look for download_from field and use that as the mirror
let body = crate::get_blob()?.bytes;
let body_json: serde_json::Value = serde_json::from_slice(&body)?;
let mirrors: &Vec<NodeId> = pkg_listing
.metadata
.as_ref()
@ -246,11 +248,14 @@ fn serve_paths(
.mirrors
.as_ref()
.ok_or(anyhow::anyhow!("No mirrors for package {package_id}"))?;
// TODO select on FE
let download_from = mirrors
.first()
.ok_or(anyhow::anyhow!("No mirrors for package {package_id}"))?;
// TODO select on FE
let download_from = body_json
.get("download_from")
.ok_or(json!(mirrors.first().ok_or(anyhow::anyhow!(
"No mirrors for package {package_id}"
))?))?
.as_str()
.ok_or(json!("download_from not a string"))?;
// TODO select on FE? or after download but before install?
let mirror = false;
let auto_update = false;
let desired_version_hash = None;

View File

@ -407,7 +407,7 @@ fn handle_receive_download(
Some(hash) => {
if download_hash != hash {
return Err(anyhow::anyhow!(
"app store: downloaded package is not latest version--rejecting download!"
"app store: downloaded package is not desired version--rejecting download! download hash: {download_hash}, desired hash: {hash}"
));
}
}
@ -422,7 +422,7 @@ fn handle_receive_download(
if let Some(latest_hash) = metadata.versions.clone().unwrap_or(vec![]).last() {
if &download_hash != latest_hash {
return Err(anyhow::anyhow!(
"app store: downloaded package is not latest version--rejecting download!"
"app store: downloaded package is not latest version--rejecting download! download hash: {download_hash}, latest hash: {latest_hash}"
));
}
} else {