mirror of
https://github.com/Yuyi-Oak/BlueArchiveToolkit.git
synced 2026-07-22 05:55:15 +08:00
feat(official-sync): 支持本地代理下载官方资源
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
//! Official JP resource download execution.
|
||||
|
||||
use crate::curl_transfer::{run_curl_with_retry, CurlRetryError};
|
||||
use crate::curl_transfer::{run_curl_with_retry_with_proxy, CurlProxyConfig, CurlRetryError};
|
||||
use crate::official_pull::OfficialResourcePullPlan;
|
||||
use crate::path_security::{
|
||||
ensure_path_within_root, ensure_safe_directory_path, ensure_safe_file_target,
|
||||
@@ -441,6 +441,7 @@ impl OfficialLocalResourceState {
|
||||
pub struct OfficialResourcePullService {
|
||||
output_root: PathBuf,
|
||||
curl_command: PathBuf,
|
||||
curl_proxy: CurlProxyConfig,
|
||||
retry_attempts: usize,
|
||||
}
|
||||
|
||||
@@ -458,10 +459,17 @@ impl OfficialResourcePullService {
|
||||
Self {
|
||||
output_root: output_root.into(),
|
||||
curl_command: curl_command.into(),
|
||||
curl_proxy: CurlProxyConfig::default(),
|
||||
retry_attempts: DEFAULT_RETRY_ATTEMPTS,
|
||||
}
|
||||
}
|
||||
|
||||
/// Sets the proxy configuration for every `curl` transfer.
|
||||
pub fn with_proxy_config(mut self, curl_proxy: CurlProxyConfig) -> Self {
|
||||
self.curl_proxy = curl_proxy;
|
||||
self
|
||||
}
|
||||
|
||||
/// Sets the number of attempts for each `curl` transfer.
|
||||
pub fn with_retry_attempts(mut self, retry_attempts: usize) -> Self {
|
||||
self.retry_attempts = retry_attempts.max(1);
|
||||
@@ -709,8 +717,13 @@ impl OfficialResourcePullService {
|
||||
return Err(format!("拒绝拉取非官方 URL:{url}"));
|
||||
}
|
||||
|
||||
let output =
|
||||
run_curl_with_retry(&self.curl_command, url, None, self.retry_attempts, || {
|
||||
let output = run_curl_with_retry_with_proxy(
|
||||
&self.curl_command,
|
||||
url,
|
||||
None,
|
||||
self.retry_attempts,
|
||||
&self.curl_proxy,
|
||||
|| {
|
||||
let mut command = Command::new(&self.curl_command);
|
||||
command
|
||||
.arg("--fail")
|
||||
@@ -720,8 +733,9 @@ impl OfficialResourcePullService {
|
||||
.arg("--url")
|
||||
.arg(url);
|
||||
command
|
||||
})
|
||||
.map_err(|error| format!("curl 拉取失败 {url}:{error}"))?;
|
||||
},
|
||||
)
|
||||
.map_err(|error| format!("curl 拉取失败 {url}:{error}"))?;
|
||||
|
||||
Ok(output.stdout)
|
||||
}
|
||||
@@ -819,11 +833,12 @@ impl OfficialResourcePullService {
|
||||
destination: &Path,
|
||||
resume: bool,
|
||||
) -> Result<(), CurlRetryError> {
|
||||
run_curl_with_retry(
|
||||
run_curl_with_retry_with_proxy(
|
||||
&self.curl_command,
|
||||
url,
|
||||
Some(destination),
|
||||
self.retry_attempts,
|
||||
&self.curl_proxy,
|
||||
|| {
|
||||
let mut command = Command::new(&self.curl_command);
|
||||
command
|
||||
|
||||
Reference in New Issue
Block a user