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
|
||||
Self::create_cache_dir(p.parent().unwrap());
|
||||
if !self.no_cache.is_match(path) {
|
||||
if !self.is_cache_invalid(&p) {
|
||||
// use cache if present
|
||||
if let Some(resp) = self.fetch_cache(&p, req).await {
|
||||
log::info!("Returning {path} from cache");
|
||||
return Some(resp);
|
||||
}
|
||||
if !self.no_cache.is_match(path) && !self.is_cache_invalid(&p) {
|
||||
// use cache if present
|
||||
if let Some(resp) = self.fetch_cache(&p, req).await {
|
||||
log::info!("Returning {path} from cache");
|
||||
return Some(resp);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -166,6 +164,7 @@ impl Mirror {
|
|||
.into_response(req),
|
||||
);
|
||||
}
|
||||
|
||||
return Some(
|
||||
actix_files::NamedFile::open_async(&p)
|
||||
.await
|
||||
|
@ -173,6 +172,7 @@ impl Mirror {
|
|||
.into_response(req),
|
||||
);
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
|
@ -193,13 +193,13 @@ impl Mirror {
|
|||
log::info!("Fetching {path} from mirrors");
|
||||
for mirror in mirrors {
|
||||
let url = format!("{mirror}{path}");
|
||||
let response = self.get_url(&url, local).await;
|
||||
if let Some(res) = response {
|
||||
if res.status().is_success() {
|
||||
return Some(res);
|
||||
if let Some(response) = self.get_url(&url, local).await {
|
||||
if response.status().is_success() {
|
||||
return Some(response);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
|
@ -220,7 +220,7 @@ impl Mirror {
|
|||
/// 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> {
|
||||
log::info!("Fetching {path}");
|
||||
let response = reqwest::get(path).await.unwrap();
|
||||
let response = reqwest::get(path).await.ok()?;
|
||||
let status_code = response.status();
|
||||
let body_bytes = response.bytes().await.ok()?;
|
||||
if status_code.is_success() {
|
||||
|
|
Loading…
Add table
Reference in a new issue