MCPcopy Create free account
hub / github.com/1jehuang/jcode / download_browser_binary

Function download_browser_binary

crates/jcode-base/src/browser.rs:408–515  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

406}
407
408async fn download_browser_binary() -> Result<()> {
409 let asset_name = get_platform_asset_name();
410 let client = jcode_provider_core::shared_http_client();
411
412 let mut request = client
413 .get(GITHUB_API_LATEST)
414 .header(reqwest::header::ACCEPT, "application/vnd.github+json");
415 // Avoid the shared unauthenticated 60 req/h per-IP GitHub bucket when a
416 // token is available (see crate::github).
417 if let Some(token) = crate::github::github_public_api_token() {
418 request = request.bearer_auth(token);
419 }
420 let release_info: serde_json::Value = request
421 .send()
422 .await?
423 .json()
424 .await
425 .context("Failed to fetch latest release info")?;
426
427 let assets = release_info["assets"]
428 .as_array()
429 .context("No assets in release")?;
430
431 // Find the browser CLI binary
432 let browser_asset = assets
433 .iter()
434 .find(|a| a["name"].as_str() == Some(&asset_name))
435 .context(format!("No asset found for platform: {}", asset_name))?;
436
437 let download_url = browser_asset["browser_download_url"]
438 .as_str()
439 .context("No download URL")?;
440
441 // Find the XPI
442 let xpi_asset = assets
443 .iter()
444 .find(|a| {
445 a["name"]
446 .as_str()
447 .map(|n| n.ends_with(".xpi"))
448 .unwrap_or(false)
449 })
450 .context("No XPI asset found in release")?;
451
452 let xpi_url = xpi_asset["browser_download_url"]
453 .as_str()
454 .context("No XPI download URL")?;
455
456 // Find the host binary
457 let host_asset_name = get_host_asset_name();
458 let host_asset = assets
459 .iter()
460 .find(|a| a["name"].as_str() == Some(&host_asset_name))
461 .with_context(|| {
462 let available = assets
463 .iter()
464 .filter_map(|a| a["name"].as_str())
465 .collect::<Vec<_>>()

Callers 1

ensure_browser_setupFunction · 0.85

Calls 14

get_platform_asset_nameFunction · 0.85
shared_http_clientFunction · 0.85
github_public_api_tokenFunction · 0.85
get_host_asset_nameFunction · 0.85
browser_binary_pathFunction · 0.85
write_file_atomicallyFunction · 0.85
xpi_pathFunction · 0.85
host_binary_pathFunction · 0.85
headerMethod · 0.80
findMethod · 0.80
iterMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected