diff --git a/Cargo.lock b/Cargo.lock index fbbef45..5628129 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1299,7 +1299,7 @@ checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" [[package]] name = "vercel-cache-helper" -version = "0.1.5" +version = "0.1.6" dependencies = [ "atty", "clap", diff --git a/Cargo.toml b/Cargo.toml index b7065c7..b198c33 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "vercel-cache-helper" -version = "0.1.5" +version = "0.1.6" edition = "2021" description = "Hello world" diff --git a/src/commands/download.rs b/src/commands/download.rs index 2edd93a..d5de3d2 100644 --- a/src/commands/download.rs +++ b/src/commands/download.rs @@ -1,4 +1,3 @@ -use indicatif::{ProgressBar, ProgressStyle}; use std::io::{Seek, Write}; pub async fn download( @@ -11,23 +10,16 @@ pub async fn download( std::env::current_dir()? }; let cache_dir = if let Some(cache_dir) = vercel_cache_helper::utils::get_cache_dir() { - println!("Cache dir found: '{:?}'", cache_dir); + println!("Cache dir found: {:?}", cache_dir); cache_dir } else { - println!("Cache dir not found."); + println!("Cache dir not found"); return Ok(()); }; let output_dir = tempfile::tempdir()?; - let pb = ProgressBar::new_spinner(); - pb.enable_steady_tick(std::time::Duration::new(0, 500)); - pb.set_style( - ProgressStyle::default_spinner() - .template("[{spinner}] {prefix} {wide_msg}") - .unwrap() - .tick_chars("/|\\- "), - ); - pb.set_message("Looking for artifacts..."); + println!("Looking for artifacts..."); + let mut output_exists_req = remote_client.exists( vercel_cache_helper::vercel::constants::FASTN_VERCEL_REMOTE_CACHE_HASH.to_string(), None, @@ -35,14 +27,13 @@ pub async fn download( let output_artifact_exists = output_exists_req.send().await?; if output_artifact_exists { - pb.finish_with_message("Remote artifact found"); + println!("Build artifacts found"); } else { - pb.finish_with_message("No remote artifact found"); + println!("Build artifacts not found"); return Ok(()); } - pb.reset(); - pb.set_message("Downloading artifacts"); + println!("Downloading build artifacts"); let mut output_dir_archive = tempfile::tempfile()?; let mut output_get_req = remote_client.get( @@ -50,32 +41,17 @@ pub async fn download( None, )?; - let mut output_get_res = output_get_req.get().await?; - let download_size = output_get_res.content_length().unwrap_or(0); - - let mut downloaded_bytes: u64 = 0; - - while let Some(chunk) = output_get_res.chunk().await? { - output_dir_archive.write_all(&chunk)?; + let output_get_res = output_get_req.get().await?; - downloaded_bytes += chunk.len() as u64; + println!("build artifacts downloaded"); - if download_size > 0 { - pb.set_position(downloaded_bytes); - pb.set_length(download_size); - } - } - - pb.finish_with_message("Remote artifacts downloaded"); + output_dir_archive.write_all(&output_get_res.bytes().await?.to_vec())?; output_dir_archive .seek(std::io::SeekFrom::Start(0)) .unwrap(); - vercel_cache_helper::utils::extract_tar_zst( - output_dir_archive, - &output_dir.path().to_path_buf(), - )?; + vercel_cache_helper::utils::extract_tar_zst(output_dir_archive, &output_dir.path().to_path_buf())?; let temp_build_dir = output_dir.path().join(".build"); let temp_cache_dir = output_dir.path().join("cache"); @@ -83,7 +59,7 @@ pub async fn download( vercel_cache_helper::utils::copy_recursively(temp_build_dir, project_dir.join(".build"))?; vercel_cache_helper::utils::copy_recursively(temp_cache_dir, cache_dir)?; - println!("Cached artifacts downloaded and copied successfully."); + println!("Remote cache retrieval completed successfully."); Ok(()) }