random mirror selection
This commit is contained in:
parent
d89760702a
commit
aeb41e5d44
3 changed files with 14 additions and 6 deletions
18
src/proxy.rs
18
src/proxy.rs
|
@ -1,9 +1,12 @@
|
|||
use std::path::{Path, PathBuf};
|
||||
|
||||
use actix_web::{HttpRequest, HttpResponse};
|
||||
use rand::prelude::*;
|
||||
use std::{
|
||||
path::{Path, PathBuf},
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
pub struct ProxyMirror {
|
||||
mirrors: Vec<String>,
|
||||
mirrors: Vec<Arc<String>>,
|
||||
data_dir: String,
|
||||
no_cache: regex::Regex,
|
||||
}
|
||||
|
@ -11,7 +14,7 @@ pub struct ProxyMirror {
|
|||
impl ProxyMirror {
|
||||
pub fn new(mirrors: Vec<String>, data_dir: &str, no_cache: &str) -> Self {
|
||||
Self {
|
||||
mirrors,
|
||||
mirrors: mirrors.into_iter().map(|x| Arc::new(x)).collect(),
|
||||
data_dir: data_dir.to_string(),
|
||||
no_cache: regex::Regex::new(no_cache).unwrap(),
|
||||
}
|
||||
|
@ -59,8 +62,11 @@ impl ProxyMirror {
|
|||
}
|
||||
}
|
||||
|
||||
for mirror in &self.mirrors {
|
||||
log::info!("Fetching {path} from mirrors");
|
||||
let mut mirrors = self.mirrors.clone();
|
||||
mirrors.shuffle(&mut rand::thread_rng());
|
||||
|
||||
log::info!("Fetching {path} from mirrors");
|
||||
for mirror in mirrors {
|
||||
let url = format!("{mirror}{path}");
|
||||
let res = self.get_url(&url, &p).await;
|
||||
if let Some(res) = res {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue