minor fixes & refactoring
This commit is contained in:
+5
-6
@@ -28,15 +28,14 @@ async fn check_one(
|
||||
}
|
||||
Err(e) => {
|
||||
if log::log_enabled!(log::Level::Debug) {
|
||||
let mut s = proxy.as_str(true);
|
||||
s.push_str(" | ");
|
||||
s.push_str(
|
||||
&e.chain()
|
||||
log::debug!(
|
||||
"{} | {}",
|
||||
proxy.as_str(true),
|
||||
e.chain()
|
||||
.map(ToString::to_string)
|
||||
.collect::<Vec<_>>()
|
||||
.join(" → "),
|
||||
.join(" → ")
|
||||
);
|
||||
log::debug!("{s}");
|
||||
}
|
||||
Err(e)
|
||||
}
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@ impl TryFrom<&str> for ProxyType {
|
||||
|
||||
fn try_from(string: &str) -> color_eyre::Result<Self> {
|
||||
match string {
|
||||
"http" | "https " => Ok(ProxyType::Http),
|
||||
"http" | "https" => Ok(ProxyType::Http),
|
||||
"socks4" => Ok(ProxyType::Socks4),
|
||||
"socks5" => Ok(ProxyType::Socks5),
|
||||
_ => Err(eyre!("Failed to convert {string} to ProxyType")),
|
||||
|
||||
+4
-4
@@ -16,7 +16,7 @@ async fn fetch_text(
|
||||
http_client: reqwest::Client,
|
||||
source: &str,
|
||||
) -> color_eyre::Result<String> {
|
||||
Ok(if is_http_url(source) {
|
||||
if is_http_url(source) {
|
||||
http_client
|
||||
.get(source)
|
||||
.timeout(config.source_timeout)
|
||||
@@ -33,14 +33,14 @@ async fn fetch_text(
|
||||
.await
|
||||
.wrap_err_with(move || {
|
||||
format!("failed to decode {source} response as text")
|
||||
})?
|
||||
})
|
||||
} else {
|
||||
tokio::fs::read_to_string(
|
||||
source.strip_prefix("file://").unwrap_or(source),
|
||||
)
|
||||
.await
|
||||
.wrap_err("failed to read file to string")?
|
||||
})
|
||||
.wrap_err("failed to read file to string")
|
||||
}
|
||||
}
|
||||
|
||||
async fn scrape_one(
|
||||
|
||||
+5
-4
@@ -19,13 +19,14 @@ impl ProxyStorage {
|
||||
}
|
||||
|
||||
pub(crate) fn get_grouped(&self) -> HashMap<ProxyType, Vec<&Proxy>> {
|
||||
let mut groups: HashMap<ProxyType, Vec<&Proxy>> = HashMap::new();
|
||||
let mut groups: HashMap<ProxyType, Vec<&Proxy>> = self
|
||||
.enabled_protocols
|
||||
.iter()
|
||||
.map(|p| (p.clone(), Vec::new()))
|
||||
.collect();
|
||||
for proxy in &self.proxies {
|
||||
groups.entry(proxy.protocol.clone()).or_default().push(proxy);
|
||||
}
|
||||
for protocol in &self.enabled_protocols {
|
||||
groups.entry(protocol.clone()).or_default();
|
||||
}
|
||||
groups
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user