Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

Commit

Permalink
add spinner to Workers Sites asset manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
EverlastingBugstopper committed Mar 17, 2020
1 parent 075b4a7 commit 590cdf7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
15 changes: 8 additions & 7 deletions src/commands/kv/bucket/mod.rs
Expand Up @@ -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;
Expand All @@ -31,22 +32,22 @@ pub const VALUE_MAX_SIZE: u64 = 10 * 1024 * 1024;
pub fn directory_keys_values(
target: &Target,
directory: &Path,
verbose: bool,
) -> Result<(Vec<KeyValuePair>, AssetManifest), failure::Error> {
match &fs::metadata(directory) {
Ok(file_type) if file_type.is_dir() => {
let mut upload_vec: Vec<KeyValuePair> = Vec::new();
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)?;

Expand Down Expand Up @@ -213,7 +214,7 @@ fn get_digest(value: String) -> Result<String, failure::Error> {
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)
}

Expand Down Expand Up @@ -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));
Expand Down
3 changes: 1 addition & 2 deletions src/commands/kv/bucket/sync.rs
Expand Up @@ -17,7 +17,6 @@ pub fn sync(
user: &GlobalUser,
namespace_id: &str,
path: &Path,
verbose: bool,
) -> Result<(Vec<KeyValuePair>, Vec<String>, AssetManifest), failure::Error> {
kv::validate_target(target)?;
// First, find all changed files in given local directory (aka files that are now stale
Expand All @@ -39,7 +38,7 @@ pub fn sync(
}

let (pairs, asset_manifest): (Vec<KeyValuePair>, AssetManifest) =
directory_keys_values(target, path, verbose)?;
directory_keys_values(target, path)?;

let to_upload = filter_files(pairs.clone(), &remote_keys);

Expand Down
2 changes: 1 addition & 1 deletion src/commands/preview/upload.rs
Expand Up @@ -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 {
Expand Down
6 changes: 2 additions & 4 deletions src/commands/publish.rs
Expand Up @@ -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 {
Expand Down Expand Up @@ -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...");
Expand Down

0 comments on commit 590cdf7

Please sign in to comment.