From 590cdf708198481f9698e363bfdec14ac1622a83 Mon Sep 17 00:00:00 2001 From: Avery Harnish Date: Tue, 17 Mar 2020 17:07:29 -0500 Subject: [PATCH] add spinner to Workers Sites asset manifest --- src/commands/kv/bucket/mod.rs | 15 ++++++++------- src/commands/kv/bucket/sync.rs | 3 +-- src/commands/preview/upload.rs | 2 +- src/commands/publish.rs | 6 ++---- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/commands/kv/bucket/mod.rs b/src/commands/kv/bucket/mod.rs index 71c1abdc8..365606a6a 100644 --- a/src/commands/kv/bucket/mod.rs +++ b/src/commands/kv/bucket/mod.rs @@ -16,6 +16,7 @@ use data_encoding::HEXLOWER; use failure::format_err; use ignore::overrides::{Override, OverrideBuilder}; use ignore::{Walk, WalkBuilder}; +use indicatif::{ProgressBar, ProgressStyle}; use sha2::{Digest, Sha256}; use cloudflare::endpoints::workerskv::write_bulk::KeyValuePair; @@ -31,7 +32,6 @@ pub const VALUE_MAX_SIZE: u64 = 10 * 1024 * 1024; pub fn directory_keys_values( target: &Target, directory: &Path, - verbose: bool, ) -> Result<(Vec, AssetManifest), failure::Error> { match &fs::metadata(directory) { Ok(file_type) if file_type.is_dir() => { @@ -39,14 +39,15 @@ pub fn directory_keys_values( let mut asset_manifest = AssetManifest::new(); let dir_walker = get_dir_iterator(target, directory)?; - + let spinner_style = + ProgressStyle::default_spinner().template("{spinner} Preparing {msg}..."); + let spinner = ProgressBar::new_spinner().with_style(spinner_style); for entry in dir_walker { + spinner.tick(); let entry = entry.unwrap(); let path = entry.path(); if path.is_file() { - if verbose { - message::working(&format!("Preparing {}", path.display())); - } + spinner.set_message(&format!("{}", path.display())); validate_file_size(&path)?; @@ -213,7 +214,7 @@ fn get_digest(value: String) -> Result { let mut hasher = Sha256::new(); hasher.input(value); let digest = hasher.result(); - let hex_digest = HEXLOWER.encode(digest.as_ref())[0..9].to_string(); + let hex_digest = HEXLOWER.encode(digest.as_ref())[0..10].to_string(); Ok(hex_digest) } @@ -527,7 +528,7 @@ mod tests { let (path, key) = generate_path_and_key(path, directory, value).unwrap(); let expected_path = "path/to/asset.ext".to_string(); - let expected_key_regex = Regex::new(r"^path/to/asset\.[0-9a-f]{64}\.ext").unwrap(); + let expected_key_regex = Regex::new(r"^path/to/asset\.[0-9a-f]{10}\.ext").unwrap(); assert_eq!(path, expected_path); assert!(expected_key_regex.is_match(&key)); diff --git a/src/commands/kv/bucket/sync.rs b/src/commands/kv/bucket/sync.rs index 58167524d..0b5a29742 100644 --- a/src/commands/kv/bucket/sync.rs +++ b/src/commands/kv/bucket/sync.rs @@ -17,7 +17,6 @@ pub fn sync( user: &GlobalUser, namespace_id: &str, path: &Path, - verbose: bool, ) -> Result<(Vec, Vec, AssetManifest), failure::Error> { kv::validate_target(target)?; // First, find all changed files in given local directory (aka files that are now stale @@ -39,7 +38,7 @@ pub fn sync( } let (pairs, asset_manifest): (Vec, AssetManifest) = - directory_keys_values(target, path, verbose)?; + directory_keys_values(target, path)?; let to_upload = filter_files(pairs.clone(), &remote_keys); diff --git a/src/commands/preview/upload.rs b/src/commands/preview/upload.rs index b3ec53726..09ecf1da4 100644 --- a/src/commands/preview/upload.rs +++ b/src/commands/preview/upload.rs @@ -65,7 +65,7 @@ pub fn upload( let path = Path::new(&site_config.bucket); let (to_upload, to_delete, asset_manifest) = - sync(target, user, &site_namespace.id, path, verbose)?; + sync(target, user, &site_namespace.id, path)?; // First, upload all existing files in given directory if verbose { diff --git a/src/commands/publish.rs b/src/commands/publish.rs index 0ef620cc8..2fa6b07fd 100644 --- a/src/commands/publish.rs +++ b/src/commands/publish.rs @@ -32,8 +32,7 @@ pub fn publish( let site_namespace = add_site_namespace(user, target, false)?; - let (to_upload, to_delete, asset_manifest) = - sync(target, user, &site_namespace.id, &path, verbose)?; + let (to_upload, to_delete, asset_manifest) = sync(target, user, &site_namespace.id, &path)?; // First, upload all existing files in bucket directory if verbose { @@ -179,8 +178,7 @@ pub fn sync_non_site_buckets( if let Some(path) = &namespace.bucket { is_using_non_site_bucket = true; validate_bucket_location(path)?; - let (to_upload, to_delete, _) = - kv::bucket::sync(target, user, &namespace.id, path, verbose)?; + let (to_upload, to_delete, _) = kv::bucket::sync(target, user, &namespace.id, path)?; // First, upload all existing files in bucket directory if verbose { message::info("Preparing to upload updated files...");