From 2ff27a1f9327bf913d7b9d6aadc703a30a297e11 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Mon, 19 Dec 2022 14:31:19 -0500 Subject: fix: hide progress bars when showing permission prompt (#17130) Also adds download bytes progress when downloading remote specifiers. Closes #16860 --- cli/file_fetcher.rs | 49 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 44 insertions(+), 5 deletions(-) (limited to 'cli/file_fetcher.rs') diff --git a/cli/file_fetcher.rs b/cli/file_fetcher.rs index f714a18ca..8738e4f48 100644 --- a/cli/file_fetcher.rs +++ b/cli/file_fetcher.rs @@ -1,15 +1,17 @@ // Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. use crate::args::CacheSetting; +use crate::auth_tokens::AuthToken; use crate::auth_tokens::AuthTokens; use crate::cache::HttpCache; use crate::colors; +use crate::http_util; use crate::http_util::resolve_redirect_from_response; use crate::http_util::CacheSemantics; -use crate::http_util::FetchOnceArgs; -use crate::http_util::FetchOnceResult; +use crate::http_util::HeadersMap; use crate::http_util::HttpClient; use crate::util::progress_bar::ProgressBar; +use crate::util::progress_bar::UpdateGuard; use crate::util::text_encoding; use data_url::DataUrl; @@ -21,6 +23,7 @@ use deno_core::error::AnyError; use deno_core::futures; use deno_core::futures::future::FutureExt; use deno_core::parking_lot::Mutex; +use deno_core::url::Url; use deno_core::ModuleSpecifier; use deno_runtime::deno_fetch::reqwest::header::HeaderValue; use deno_runtime::deno_fetch::reqwest::header::ACCEPT; @@ -470,6 +473,7 @@ impl FileFetcher { maybe_accept: maybe_accept.clone(), maybe_etag, maybe_auth_token, + maybe_progress_guard: maybe_progress_guard.as_ref(), }, ) .await? @@ -637,14 +641,30 @@ impl FileFetcher { } } +#[derive(Debug, Eq, PartialEq)] +enum FetchOnceResult { + Code(Vec, HeadersMap), + NotModified, + Redirect(Url, HeadersMap), +} + +#[derive(Debug)] +struct FetchOnceArgs<'a> { + pub url: Url, + pub maybe_accept: Option, + pub maybe_etag: Option, + pub maybe_auth_token: Option, + pub maybe_progress_guard: Option<&'a UpdateGuard>, +} + /// Asynchronously fetches the given HTTP URL one pass only. /// If no redirect is present and no error occurs, /// yields Code(ResultPayload). /// If redirect occurs, does not follow and /// yields Redirect(url). -async fn fetch_once( +async fn fetch_once<'a>( http_client: &HttpClient, - args: FetchOnceArgs, + args: FetchOnceArgs<'a>, ) -> Result { let mut request = http_client.get_no_redirect(args.url.clone()); @@ -710,7 +730,11 @@ async fn fetch_once( return Err(err); } - let body = response.bytes().await?.to_vec(); + let body = http_util::get_response_body_with_progress( + response, + args.maybe_progress_guard, + ) + .await?; Ok(FetchOnceResult::Code(body, result_headers)) } @@ -1760,6 +1784,7 @@ mod tests { maybe_accept: None, maybe_etag: None, maybe_auth_token: None, + maybe_progress_guard: None, }, ) .await; @@ -1787,6 +1812,7 @@ mod tests { maybe_accept: None, maybe_etag: None, maybe_auth_token: None, + maybe_progress_guard: None, }, ) .await; @@ -1815,6 +1841,7 @@ mod tests { maybe_accept: None, maybe_etag: None, maybe_auth_token: None, + maybe_progress_guard: None, }, ) .await; @@ -1837,6 +1864,7 @@ mod tests { maybe_accept: None, maybe_etag: Some("33a64df551425fcc55e".to_string()), maybe_auth_token: None, + maybe_progress_guard: None, }, ) .await; @@ -1857,6 +1885,7 @@ mod tests { maybe_accept: None, maybe_etag: None, maybe_auth_token: None, + maybe_progress_guard: None, }, ) .await; @@ -1887,6 +1916,7 @@ mod tests { maybe_accept: Some("application/json".to_string()), maybe_etag: None, maybe_auth_token: None, + maybe_progress_guard: None, }, ) .await; @@ -1913,6 +1943,7 @@ mod tests { maybe_accept: None, maybe_etag: None, maybe_auth_token: None, + maybe_progress_guard: None, }, ) .await; @@ -1953,6 +1984,7 @@ mod tests { maybe_accept: None, maybe_etag: None, maybe_auth_token: None, + maybe_progress_guard: None, }, ) .await; @@ -1990,6 +2022,7 @@ mod tests { maybe_accept: None, maybe_etag: None, maybe_auth_token: None, + maybe_progress_guard: None, }, ) .await; @@ -2025,6 +2058,7 @@ mod tests { maybe_accept: None, maybe_etag: None, maybe_auth_token: None, + maybe_progress_guard: None, }, ) .await; @@ -2066,6 +2100,7 @@ mod tests { maybe_accept: None, maybe_etag: None, maybe_auth_token: None, + maybe_progress_guard: None, }, ) .await; @@ -2110,6 +2145,7 @@ mod tests { maybe_accept: None, maybe_etag: None, maybe_auth_token: None, + maybe_progress_guard: None, }, ) .await; @@ -2133,6 +2169,7 @@ mod tests { maybe_accept: None, maybe_etag: Some("33a64df551425fcc55e".to_string()), maybe_auth_token: None, + maybe_progress_guard: None, }, ) .await; @@ -2170,6 +2207,7 @@ mod tests { maybe_accept: None, maybe_etag: None, maybe_auth_token: None, + maybe_progress_guard: None, }, ) .await; @@ -2200,6 +2238,7 @@ mod tests { maybe_accept: None, maybe_etag: None, maybe_auth_token: None, + maybe_progress_guard: None, }, ) .await; -- cgit v1.2.3