mirror of
https://github.com/getnora-io/nora.git
synced 2026-04-12 13:50:31 +00:00
style: apply rustfmt to registry handlers
This commit is contained in:
@@ -110,7 +110,11 @@ async fn upload(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn fetch_from_proxy(client: &reqwest::Client, url: &str, timeout_secs: u64) -> Result<Vec<u8>, ()> {
|
async fn fetch_from_proxy(
|
||||||
|
client: &reqwest::Client,
|
||||||
|
url: &str,
|
||||||
|
timeout_secs: u64,
|
||||||
|
) -> Result<Vec<u8>, ()> {
|
||||||
let response = client
|
let response = client
|
||||||
.get(url)
|
.get(url)
|
||||||
.timeout(Duration::from_secs(timeout_secs))
|
.timeout(Duration::from_secs(timeout_secs))
|
||||||
|
|||||||
@@ -55,7 +55,9 @@ async fn handle_request(State(state): State<Arc<AppState>>, Path(path): Path<Str
|
|||||||
if let Some(proxy_url) = &state.config.npm.proxy {
|
if let Some(proxy_url) = &state.config.npm.proxy {
|
||||||
let url = format!("{}/{}", proxy_url.trim_end_matches('/'), path);
|
let url = format!("{}/{}", proxy_url.trim_end_matches('/'), path);
|
||||||
|
|
||||||
if let Ok(data) = fetch_from_proxy(&state.http_client, &url, state.config.npm.proxy_timeout).await {
|
if let Ok(data) =
|
||||||
|
fetch_from_proxy(&state.http_client, &url, state.config.npm.proxy_timeout).await
|
||||||
|
{
|
||||||
if is_tarball {
|
if is_tarball {
|
||||||
state.metrics.record_download("npm");
|
state.metrics.record_download("npm");
|
||||||
state.metrics.record_cache_miss();
|
state.metrics.record_cache_miss();
|
||||||
@@ -85,7 +87,11 @@ async fn handle_request(State(state): State<Arc<AppState>>, Path(path): Path<Str
|
|||||||
StatusCode::NOT_FOUND.into_response()
|
StatusCode::NOT_FOUND.into_response()
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn fetch_from_proxy(client: &reqwest::Client, url: &str, timeout_secs: u64) -> Result<Vec<u8>, ()> {
|
async fn fetch_from_proxy(
|
||||||
|
client: &reqwest::Client,
|
||||||
|
url: &str,
|
||||||
|
timeout_secs: u64,
|
||||||
|
) -> Result<Vec<u8>, ()> {
|
||||||
let response = client
|
let response = client
|
||||||
.get(url)
|
.get(url)
|
||||||
.timeout(Duration::from_secs(timeout_secs))
|
.timeout(Duration::from_secs(timeout_secs))
|
||||||
|
|||||||
@@ -85,7 +85,9 @@ async fn package_versions(
|
|||||||
if let Some(proxy_url) = &state.config.pypi.proxy {
|
if let Some(proxy_url) = &state.config.pypi.proxy {
|
||||||
let url = format!("{}/{}/", proxy_url.trim_end_matches('/'), normalized);
|
let url = format!("{}/{}/", proxy_url.trim_end_matches('/'), normalized);
|
||||||
|
|
||||||
if let Ok(html) = fetch_package_page(&state.http_client, &url, state.config.pypi.proxy_timeout).await {
|
if let Ok(html) =
|
||||||
|
fetch_package_page(&state.http_client, &url, state.config.pypi.proxy_timeout).await
|
||||||
|
{
|
||||||
// Rewrite URLs in the HTML to point to our registry
|
// Rewrite URLs in the HTML to point to our registry
|
||||||
let rewritten = rewrite_pypi_links(&html, &normalized);
|
let rewritten = rewrite_pypi_links(&html, &normalized);
|
||||||
return (StatusCode::OK, Html(rewritten)).into_response();
|
return (StatusCode::OK, Html(rewritten)).into_response();
|
||||||
@@ -130,10 +132,22 @@ async fn download_file(
|
|||||||
// First, fetch the package page to find the actual download URL
|
// First, fetch the package page to find the actual download URL
|
||||||
let page_url = format!("{}/{}/", proxy_url.trim_end_matches('/'), normalized);
|
let page_url = format!("{}/{}/", proxy_url.trim_end_matches('/'), normalized);
|
||||||
|
|
||||||
if let Ok(html) = fetch_package_page(&state.http_client, &page_url, state.config.pypi.proxy_timeout).await {
|
if let Ok(html) = fetch_package_page(
|
||||||
|
&state.http_client,
|
||||||
|
&page_url,
|
||||||
|
state.config.pypi.proxy_timeout,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
// Find the URL for this specific file
|
// Find the URL for this specific file
|
||||||
if let Some(file_url) = find_file_url(&html, &filename) {
|
if let Some(file_url) = find_file_url(&html, &filename) {
|
||||||
if let Ok(data) = fetch_file(&state.http_client, &file_url, state.config.pypi.proxy_timeout).await {
|
if let Ok(data) = fetch_file(
|
||||||
|
&state.http_client,
|
||||||
|
&file_url,
|
||||||
|
state.config.pypi.proxy_timeout,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
state.metrics.record_download("pypi");
|
state.metrics.record_download("pypi");
|
||||||
state.metrics.record_cache_miss();
|
state.metrics.record_cache_miss();
|
||||||
state.activity.push(ActivityEntry::new(
|
state.activity.push(ActivityEntry::new(
|
||||||
@@ -177,7 +191,11 @@ fn normalize_name(name: &str) -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Fetch package page from upstream
|
/// Fetch package page from upstream
|
||||||
async fn fetch_package_page(client: &reqwest::Client, url: &str, timeout_secs: u64) -> Result<String, ()> {
|
async fn fetch_package_page(
|
||||||
|
client: &reqwest::Client,
|
||||||
|
url: &str,
|
||||||
|
timeout_secs: u64,
|
||||||
|
) -> Result<String, ()> {
|
||||||
let response = client
|
let response = client
|
||||||
.get(url)
|
.get(url)
|
||||||
.timeout(Duration::from_secs(timeout_secs))
|
.timeout(Duration::from_secs(timeout_secs))
|
||||||
|
|||||||
Reference in New Issue
Block a user