diff options
| author | mtul0729 <52401682+mtul0729@users.noreply.github.com> | 2025-02-02 08:00:01 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-02-02 08:00:01 +0800 |
| commit | 79550fd0f3719244a30b00de6de58ca8474919f1 (patch) | |
| tree | 5afac911ce18ec8fc192489efd57ace444cc7636 | |
| parent | 843e66fafc080fc8170ca69175be003d297fef32 (diff) | |
| download | aichat-79550fd0f3719244a30b00de6de58ca8474919f1.tar.gz | |
refactor: several improvements (#1138)
| -rw-r--r-- | src/client/common.rs | 5 | ||||
| -rw-r--r-- | src/render/markdown.rs | 2 | ||||
| -rw-r--r-- | src/utils/mod.rs | 13 | ||||
| -rw-r--r-- | src/utils/request.rs | 1 |
4 files changed, 9 insertions, 12 deletions
diff --git a/src/client/common.rs b/src/client/common.rs index 322fc5c..d8909ee 100644 --- a/src/client/common.rs +++ b/src/client/common.rs @@ -44,8 +44,9 @@ pub trait Client: Sync + Send { let mut builder = ReqwestClient::builder(); let extra = self.extra_config(); let timeout = extra.and_then(|v| v.connect_timeout).unwrap_or(10); - let proxy = extra.and_then(|v| v.proxy.clone()); - builder = set_proxy(builder, proxy.as_ref())?; + if let Some(proxy) = extra.and_then(|v| v.proxy.as_deref()) { + builder = set_proxy(builder, proxy)?; + } if let Some(user_agent) = self.global_config().read().user_agent.as_ref() { builder = builder.user_agent(user_agent); } diff --git a/src/render/markdown.rs b/src/render/markdown.rs index b8710b7..f5f532d 100644 --- a/src/render/markdown.rs +++ b/src/render/markdown.rs @@ -7,7 +7,7 @@ use syntect::highlighting::{Color as SyntectColor, FontStyle, Style, Theme}; use syntect::parsing::SyntaxSet; use syntect::{easy::HighlightLines, parsing::SyntaxReference}; -/// Comes from https://github.com/sharkdp/bat/raw/5e77ca37e89c873e4490b42ff556370dc5c6ba4f/assets/syntaxes.bin +/// Comes from <https://github.com/sharkdp/bat/raw/5e77ca37e89c873e4490b42ff556370dc5c6ba4f/assets/syntaxes.bin> const SYNTAXES: &[u8] = include_bytes!("../../assets/syntaxes.bin"); lazy_static::lazy_static! { diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 7aa1801..9dde751 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -217,15 +217,12 @@ pub fn is_url(path: &str) -> bool { pub fn set_proxy( mut builder: reqwest::ClientBuilder, - proxy: Option<&String>, + proxy: &str, ) -> Result<reqwest::ClientBuilder> { - if let Some(proxy) = proxy { - builder = builder.no_proxy(); - if !proxy.is_empty() && proxy != "-" { - builder = builder.proxy( - reqwest::Proxy::all(proxy).with_context(|| format!("Invalid proxy `{proxy}`"))?, - ); - } + builder = builder.no_proxy(); + if !proxy.is_empty() && proxy != "-" { + builder = builder + .proxy(reqwest::Proxy::all(proxy).with_context(|| format!("Invalid proxy `{proxy}`"))?); }; Ok(builder) } diff --git a/src/utils/request.rs b/src/utils/request.rs index a479e0e..efcd102 100644 --- a/src/utils/request.rs +++ b/src/utils/request.rs @@ -29,7 +29,6 @@ const USER_AGENT: &str = "curl/8.6.0"; lazy_static::lazy_static! { static ref CLIENT: Result<reqwest::Client> = { let builder = reqwest::ClientBuilder::new().timeout(Duration::from_secs(30)); - let builder = set_proxy(builder, None)?; let client = builder.build()?; Ok(client) }; |
