refactor(subscription): pass the proxy directly to each download

This commit is contained in:
Tunglies
2026-12-03 19:38:23 +08:00
parent c742a9a17c
commit 83a520ea19
3 changed files with 72 additions and 77 deletions
+1 -1
View File
@@ -13,7 +13,7 @@ mod verge;
pub(crate) use self::config::Config;
pub(crate) use self::prfitem::{
build_remote_profile, download_subscription, prepare_remote_refresh, read_profile_item_file,
build_remote_profile, download_subscription, prepare_remote_refresh, read_profile_item_file, subscription_proxy,
};
pub use self::{clash::*, encrypt::*, mixed_port::*, profiles::*, verge::*};
pub use clash_verge_profile::{PrfExtra, PrfItem, PrfOption, PrfSelected};
+16 -19
View File
@@ -140,7 +140,7 @@ pub(crate) async fn build_remote_profile(
desc: Option<&String>,
option: Option<&PrfOption>,
) -> Result<PrfItem> {
let mut downloaded = download_subscription(url, option).await?;
let mut downloaded = download_subscription(url, option, subscription_proxy(option)).await?;
let uid: String = help::get_uid("R").into();
let file = format!("{uid}.yaml").into();
let name = name
@@ -172,31 +172,28 @@ pub(crate) async fn build_remote_profile(
})
}
pub(crate) async fn download_subscription(url: &str, option: Option<&PrfOption>) -> Result<DownloadedSubscription> {
let with_proxy = option.is_some_and(|o| o.with_proxy.unwrap_or(false));
let self_proxy = option.is_some_and(|o| o.self_proxy.unwrap_or(false));
let accept_invalid_certs = option.is_some_and(|o| o.danger_accept_invalid_certs.unwrap_or(false));
let user_agent = option.and_then(|o| o.user_agent.clone());
let timeout = option.and_then(|o| o.timeout_seconds).unwrap_or(20);
let proxy_type = if self_proxy {
pub(crate) fn subscription_proxy(options: Option<&PrfOption>) -> ProxyType {
if options.and_then(|options| options.self_proxy) == Some(true) {
ProxyType::Localhost
} else if with_proxy {
} else if options.and_then(|options| options.with_proxy) == Some(true) {
ProxyType::System
} else {
ProxyType::None
};
}
}
pub(crate) async fn download_subscription(
url: &str,
option: Option<&PrfOption>,
proxy: ProxyType,
) -> Result<DownloadedSubscription> {
let accept_invalid_certs = option.is_some_and(|o| o.danger_accept_invalid_certs.unwrap_or(false));
let user_agent = option.and_then(|o| o.user_agent.clone());
let timeout = option.and_then(|o| o.timeout_seconds).unwrap_or(20);
let url = fix_dirty_url(url)?;
let resp = match NetworkManager::new()
.get(
url.as_str(),
proxy_type,
Some(timeout),
user_agent,
accept_invalid_certs,
)
.get(url.as_str(), proxy, Some(timeout), user_agent, accept_invalid_certs)
.await
{
Ok(r) => r,
@@ -416,7 +413,7 @@ mod tests {
update_interval: None,
..option
};
let downloaded = download_subscription(&url, Some(&refresh_option)).await?;
let downloaded = download_subscription(&url, Some(&refresh_option), ProxyType::None).await?;
let refresh = prepare_remote_refresh(downloaded, Some(&refresh_option)).await?;
server.await??;
assert_eq!(item.itype.as_deref(), Some("remote"));