feat(official-sync): 支持本地代理下载官方资源

This commit is contained in:
2026-07-16 00:12:27 +08:00
parent 169822abaf
commit c123f6c0dc
10 changed files with 481 additions and 40 deletions
+18 -4
View File
@@ -5,6 +5,7 @@
//! callers: discover current official state, compare remote markers, audit the
//! local manifest, repair/download when needed, then return a structured report.
use crate::curl_transfer::{resolve_curl_proxy, CurlProxyConfig};
use crate::path_security::{
ensure_path_within_root, ensure_safe_directory_path, ensure_safe_file_target,
read_file_no_symlink, validate_output_root, write_file_atomic, STATE_FILE_MODE,
@@ -79,6 +80,8 @@ pub struct OfficialUpdateConfig {
pub snapshot_path: Option<PathBuf>,
/// Curl command used by the current infrastructure downloader.
pub curl_command: PathBuf,
/// Proxy selection used by all official `curl` transfers.
pub curl_proxy: CurlProxyConfig,
/// Unzip command used when a metadata change requires GameMainConfig parsing.
pub unzip_command: PathBuf,
/// Dry run reports decisions and optional plan URLs without writing sync state.
@@ -105,6 +108,7 @@ impl Default for OfficialUpdateConfig {
output_root: PathBuf::from("./bat-resources"),
snapshot_path: None,
curl_command: PathBuf::from("curl"),
curl_proxy: CurlProxyConfig::default(),
unzip_command: PathBuf::from("unzip"),
dry_run: false,
plan: false,
@@ -827,6 +831,10 @@ impl OfficialUpdateService {
));
check_shutdown_requested(&mut should_cancel)?;
validate_update_paths(config).map_err(anyhow::Error::msg)?;
progress(OfficialUpdateProgress::new(
"proxy",
resolve_curl_proxy(&config.curl_proxy).human_summary(),
));
let _lock = if config.dry_run {
progress(OfficialUpdateProgress::new("lock", "试运行:跳过状态锁"));
@@ -862,7 +870,8 @@ impl OfficialUpdateService {
let fetcher = OfficialResourcePullService::with_curl_command(
&active_resource_root,
&config.curl_command,
);
)
.with_proxy_config(config.curl_proxy.clone());
let snapshot_path = snapshot_path_for(config, &active_resource_root);
let bootstrap_cache_path = config.bootstrap_cache_path();
@@ -878,6 +887,7 @@ impl OfficialUpdateService {
Some(resolve_bootstrap(
&config.launcher_version,
&config.curl_command,
&config.curl_proxy,
&config.unzip_command,
&bootstrap_cache_path,
!config.dry_run,
@@ -1256,7 +1266,8 @@ impl OfficialUpdateService {
let staging_fetcher = OfficialResourcePullService::with_curl_command(
&publish_plan.staging_path,
&config.curl_command,
);
)
.with_proxy_config(config.curl_proxy.clone());
report.staging_path = Some(publish_plan.staging_path.clone());
report.snapshot_path = staging_snapshot_path.clone();
report.download_manifest = staging_fetcher.download_manifest_path();
@@ -2214,6 +2225,7 @@ fn game_main_config_snapshot(config: &YostarJpGameMainConfig) -> GameMainConfigS
fn resolve_bootstrap(
launcher_version: &str,
curl_command: &Path,
curl_proxy: &CurlProxyConfig,
unzip_command: &Path,
cache_path: &Path,
write_cache: bool,
@@ -2224,7 +2236,8 @@ fn resolve_bootstrap(
let launcher = OfficialLauncherBootstrapService::with_curl_command(
launcher_version,
curl_command.to_string_lossy().to_string(),
);
)
.with_proxy_config(curl_proxy.clone());
progress(OfficialUpdateProgress::new(
"launcher",
"正在拉取官方启动器游戏配置和远端 manifest",
@@ -2272,7 +2285,8 @@ fn resolve_bootstrap(
launcher_version,
curl_command.to_path_buf(),
unzip_command.to_path_buf(),
);
)
.with_proxy_config(curl_proxy.clone());
let bootstrap = bootstrapper.fetch_bootstrap().map_err(anyhow::Error::msg)?;
check_shutdown_requested(should_cancel)?;
let launcher_metadata = LauncherMetadataSnapshot {