mirror of
https://github.com/uqbar-dao/nectar.git
synced 2024-11-26 00:32:45 +03:00
app_store: allow frontend to select mirror to use via POST body
This commit is contained in:
parent
b4c44cc79f
commit
acebc82a59
@ -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;
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user