mirror of
https://github.com/denoland/deno.git
synced 2025-08-04 02:48:24 +00:00
fix: hide progress bars when showing permission prompt (#17130)
Also adds download bytes progress when downloading remote specifiers. Closes #16860
This commit is contained in:
parent
5a8adc342b
commit
2ff27a1f93
6 changed files with 120 additions and 86 deletions
|
@ -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<u8>, HeadersMap),
|
||||
NotModified,
|
||||
Redirect(Url, HeadersMap),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct FetchOnceArgs<'a> {
|
||||
pub url: Url,
|
||||
pub maybe_accept: Option<String>,
|
||||
pub maybe_etag: Option<String>,
|
||||
pub maybe_auth_token: Option<AuthToken>,
|
||||
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<FetchOnceResult, AnyError> {
|
||||
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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue