V1 of laucher
This commit is contained in:
@@ -121,6 +121,50 @@ pub async fn end_session(http: &reqwest::Client, mcp_url: &str, launcher_token:
|
||||
.await;
|
||||
}
|
||||
|
||||
/// A DHP's answer to "may this PC download a whole version now?".
|
||||
pub enum InstallSlot {
|
||||
/// Go ahead; renew before `lease_sec` runs out.
|
||||
Granted { lease_sec: u64 },
|
||||
/// Wait: this many PCs are downloading or waiting ahead of this one.
|
||||
Queued { ahead: u64 },
|
||||
/// The DHP does not hand out slots (older service): just install.
|
||||
NotOffered,
|
||||
}
|
||||
|
||||
/// Ask for, or renew, this PC's install slot.
|
||||
pub async fn claim_install(http: &reqwest::Client, site_url: &str, token: &str, install_id: &str) -> InstallSlot {
|
||||
let sent = http
|
||||
.post(format!("{site_url}/v1/install/claim"))
|
||||
.bearer_auth(token)
|
||||
.json(&serde_json::json!({ "install_id": install_id }))
|
||||
.timeout(Duration::from_secs(10))
|
||||
.send()
|
||||
.await;
|
||||
let Ok(response) = sent else { return InstallSlot::NotOffered };
|
||||
if response.status() == StatusCode::NOT_FOUND {
|
||||
return InstallSlot::NotOffered;
|
||||
}
|
||||
if !response.status().is_success() {
|
||||
return InstallSlot::NotOffered;
|
||||
}
|
||||
let body: serde_json::Value = response.json().await.unwrap_or_default();
|
||||
if body.get("granted").and_then(|g| g.as_bool()).unwrap_or(true) {
|
||||
return InstallSlot::Granted { lease_sec: body.get("lease_sec").and_then(|l| l.as_u64()).unwrap_or(120) };
|
||||
}
|
||||
InstallSlot::Queued { ahead: body.get("ahead").and_then(|a| a.as_u64()).unwrap_or(0) }
|
||||
}
|
||||
|
||||
/// Give the slot back. Best effort: an unreleased slot simply expires.
|
||||
pub async fn release_install(http: &reqwest::Client, site_url: &str, token: &str, install_id: &str) {
|
||||
let _ = http
|
||||
.post(format!("{site_url}/v1/install/release"))
|
||||
.bearer_auth(token)
|
||||
.json(&serde_json::json!({ "install_id": install_id }))
|
||||
.timeout(Duration::from_secs(5))
|
||||
.send()
|
||||
.await;
|
||||
}
|
||||
|
||||
pub async fn notes(http: &reqwest::Client, site_url: &str, token: &str, version: &str) -> Result<String, String> {
|
||||
let response = http
|
||||
.get(format!("{site_url}/v1/versions/{version}/notes"))
|
||||
|
||||
Reference in New Issue
Block a user