use crate::net::download;
use nitro_shared::util::{ARCH_STRING, OS_STRING};
use anyhow::Context;
use reqwest::Client;
pub mod adoptium {
use anyhow::bail;
use serde::Deserialize;
use super::*;
pub async fn get_latest(major_version: &str, client: &Client) -> anyhow::Result<PackageFormat> {
let url = json_url(major_version);
let mut manifest = download::json::<Vec<PackageFormat>>(&url, client)
.await
.context("Failed to download manifest of Adoptium versions")?;
if manifest.is_empty() {
bail!("A valid installation was not found");
}
let version = manifest.swap_remove(0);
Ok(version)
}
fn json_url(major_version: &str) -> String {
format!(
"https://api.adoptium.net/v3/assets/latest/{major_version}/hotspot?image_type=jre&vendor=eclipse&architecture={}&os={}",
get_arch_arg(),
get_os_arg(),
)
}
fn get_os_arg() -> &'static str {
if cfg!(target_os = "macos") {
"mac"
} else {
OS_STRING
}
}
fn get_arch_arg() -> &'static str {
if cfg!(target_arch = "x86_64") {
"x64"
} else {
ARCH_STRING
}
}
#[derive(Deserialize, Debug)]
pub struct PackageFormat {
pub binary: Binary,
pub release_name: String,
}
#[derive(Deserialize, Debug)]
pub struct Binary {
pub package: BinaryPackage,
}
#[derive(Deserialize, Debug)]
pub struct BinaryPackage {
pub link: String,
}
}