refactor
This commit is contained in:
parent
fd581bf9d9
commit
704530ee41
2 changed files with 357 additions and 261 deletions
594
Cargo.lock
generated
594
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
24
src/proxy.rs
24
src/proxy.rs
|
@ -127,13 +127,11 @@ impl Mirror {
|
||||||
|
|
||||||
// check if cache should be used
|
// check if cache should be used
|
||||||
Self::create_cache_dir(p.parent().unwrap());
|
Self::create_cache_dir(p.parent().unwrap());
|
||||||
if !self.no_cache.is_match(path) {
|
if !self.no_cache.is_match(path) && !self.is_cache_invalid(&p) {
|
||||||
if !self.is_cache_invalid(&p) {
|
// use cache if present
|
||||||
// use cache if present
|
if let Some(resp) = self.fetch_cache(&p, req).await {
|
||||||
if let Some(resp) = self.fetch_cache(&p, req).await {
|
log::info!("Returning {path} from cache");
|
||||||
log::info!("Returning {path} from cache");
|
return Some(resp);
|
||||||
return Some(resp);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,6 +164,7 @@ impl Mirror {
|
||||||
.into_response(req),
|
.into_response(req),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Some(
|
return Some(
|
||||||
actix_files::NamedFile::open_async(&p)
|
actix_files::NamedFile::open_async(&p)
|
||||||
.await
|
.await
|
||||||
|
@ -173,6 +172,7 @@ impl Mirror {
|
||||||
.into_response(req),
|
.into_response(req),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,13 +193,13 @@ impl Mirror {
|
||||||
log::info!("Fetching {path} from mirrors");
|
log::info!("Fetching {path} from mirrors");
|
||||||
for mirror in mirrors {
|
for mirror in mirrors {
|
||||||
let url = format!("{mirror}{path}");
|
let url = format!("{mirror}{path}");
|
||||||
let response = self.get_url(&url, local).await;
|
if let Some(response) = self.get_url(&url, local).await {
|
||||||
if let Some(res) = response {
|
if response.status().is_success() {
|
||||||
if res.status().is_success() {
|
return Some(response);
|
||||||
return Some(res);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -220,7 +220,7 @@ impl Mirror {
|
||||||
/// or `None` if there was an error during the request or response retrieval.
|
/// or `None` if there was an error during the request or response retrieval.
|
||||||
pub async fn get_url(&self, path: &str, save: &PathBuf) -> Option<HttpResponse> {
|
pub async fn get_url(&self, path: &str, save: &PathBuf) -> Option<HttpResponse> {
|
||||||
log::info!("Fetching {path}");
|
log::info!("Fetching {path}");
|
||||||
let response = reqwest::get(path).await.unwrap();
|
let response = reqwest::get(path).await.ok()?;
|
||||||
let status_code = response.status();
|
let status_code = response.status();
|
||||||
let body_bytes = response.bytes().await.ok()?;
|
let body_bytes = response.bytes().await.ok()?;
|
||||||
if status_code.is_success() {
|
if status_code.is_success() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue