diff --git a/src/commands/upload.rs b/src/commands/upload.rs index 6206404..33b9e03 100644 --- a/src/commands/upload.rs +++ b/src/commands/upload.rs @@ -1,4 +1,4 @@ -use std::io::Read; +use std::io::{Read, Seek}; pub async fn upload( remote_client: vercel_cache_helper::vercel::remote_cache_client::RemoteClient, @@ -26,17 +26,19 @@ pub async fn upload( vercel_cache_helper::utils::create_tar_gz_archive(&cache_dir, &cache_dir_archive)?; vercel_cache_helper::utils::create_tar_gz_archive(&build_dir, &build_dir_archive)?; + build_dir_archive.seek(std::io::SeekFrom::Start(0)).unwrap(); + cache_dir_archive.seek(std::io::SeekFrom::Start(0)).unwrap(); + let mut build_archive_buf: Vec = Vec::new(); let mut cache_archive_buf: Vec = Vec::new(); - build_dir_archive.read_to_end(&mut build_archive_buf)?; - cache_dir_archive.read_to_end(&mut cache_archive_buf)?; + println!("{:?}", build_dir_archive.metadata()); - let build_archive_size = build_dir_archive.metadata()?.len(); - let cache_archive_size = cache_dir_archive.metadata()?.len(); + let build_archive_size = build_dir_archive.read_to_end(&mut build_archive_buf)?; + let cache_archive_size = cache_dir_archive.read_to_end(&mut cache_archive_buf)?; - println!("Build archive size: {} bytes", build_archive_size); - println!("Cache archive size: {} bytes", cache_archive_size); + println!("Build archive bytes read: {} bytes", build_archive_size); + println!("Cache archive bytes read: {} bytes", cache_archive_size); let build_archive_hash = vercel_cache_helper::utils::generate_hash(&build_archive_buf); let cache_dir_hash = vercel_cache_helper::utils::generate_hash(&cache_archive_buf); diff --git a/src/vercel/artifact.rs b/src/vercel/artifact.rs index 9e3b459..3835cb7 100644 --- a/src/vercel/artifact.rs +++ b/src/vercel/artifact.rs @@ -4,7 +4,7 @@ pub struct ArtifactOptions { } trait RequestHeaders { - fn get_headers(&self, method: &str, content_len: Option) -> reqwest::header::HeaderMap; + fn get_headers(&self, method: &str, content_len: Option) -> reqwest::header::HeaderMap; } // Define the base struct with common fields and behavior. @@ -33,7 +33,7 @@ impl ArtifactBaseRequest { // Implement the trait for the base struct. impl RequestHeaders for ArtifactBaseRequest { - fn get_headers(&self, method: &str, content_len: Option) -> reqwest::header::HeaderMap { + fn get_headers(&self, method: &str, content_len: Option) -> reqwest::header::HeaderMap { let mut headers = reqwest::header::HeaderMap::new(); headers.insert( @@ -108,9 +108,13 @@ impl ArtifactPutRequest { artifact.read_to_end(&mut body).await?; + let headers = self.0.get_headers("PUT", None); + + println!("Headers: {:?}", headers); + let response = client .put(&self.0.url) - .headers(self.0.get_headers("PUT", None)) + .headers(headers) .body(body) .send() .await?; @@ -121,13 +125,19 @@ impl ArtifactPutRequest { pub async fn buffer( &mut self, artifact: &mut [u8], - content_len: u64 + content_len: usize ) -> vercel_cache_helper::Result { let client = reqwest::Client::new(); + println!("{:?}", &artifact); + + let headers = self.0.get_headers("PUT", Some(content_len)); + + println!("Headers: {:?}", headers); + let response = client .put(&self.0.url) - .headers(self.0.get_headers("PUT", Some(content_len))) + .headers(headers) .body(artifact.to_owned()) .send() .await?;