From bee137c56334f0162a848ad43db9fcf86eb73d82 Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Sun, 19 Oct 2025 23:03:20 +0800 Subject: [PATCH] feat: udpate connect.rs --- connect-rs/src/main.rs | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/connect-rs/src/main.rs b/connect-rs/src/main.rs index 320d57c..bb8d365 100755 --- a/connect-rs/src/main.rs +++ b/connect-rs/src/main.rs @@ -15,12 +15,15 @@ use crypto::digest::Digest; use crypto::sha2::Sha256; use keyring::Entry; use rust_util::{ - failure, information, opt_result, simple_error, success, util_cmd, util_file, XResult, + XResult, failure, information, opt_result, simple_error, success, util_cmd, util_env, util_file, }; use serde_json::Value; use std::fs; use std::process::Command; +const PAC_FILE: &str = "__proxy__.pac"; +const ENV_CONNECT_PAC_FILE_PATH: &str = "CONNECT_PAC_FILE_PATH"; + #[derive(Debug, Parser)] #[command(name = "connect-rs", bin_name = "connect.rs")] #[command(about = "Connect to the world", long_about = None)] @@ -85,8 +88,8 @@ fn update_pac_file_ignore_error() { fn update_pac_file() -> XResult<()> { let digest = get_pac_digest()?; - let pac_file = "__proxy__.pac"; - let pac_file_content = util_file::read_file_content(pac_file)?; + let pac_file_full_path = get_pac_file_full_path(); + let pac_file_content = util_file::read_file_content(&pac_file_full_path)?; let mut sha256 = Sha256::new(); sha256.input(pac_file_content.as_bytes()); @@ -105,9 +108,9 @@ fn update_pac_file() -> XResult<()> { let pac_content = get_pac_content()?; opt_result!( - fs::write(pac_file, pac_content), + fs::write(&pac_file_full_path, pac_content), "Write file {}, failed: {}", - pac_file + &pac_file_full_path ); success!("Pac file updated successfully."); @@ -166,6 +169,14 @@ fn get_pac_content() -> XResult { Ok(pac_content_text) } +fn get_pac_file_full_path() -> String { + let connect_pac_file_path = match util_env::env_var(ENV_CONNECT_PAC_FILE_PATH) { + Some(connect_pac_file_path) => connect_pac_file_path, + None => return PAC_FILE.to_string(), + }; + util_file::join_path(&connect_pac_file_path, PAC_FILE) +} + fn get_pac_digest() -> XResult { let auth_token = get_pac_auth_token()?; let url = format!( @@ -214,5 +225,5 @@ fn get_pac_auth_token() -> XResult { )) } -// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20251019T152450+08:00.MEUCIQDzZTpk54DYe9u/FrsQ -// 7OPRmEHLjUelAZUevqPHa7nFEgIgf/Xw73PwCE3miSNXmXawWh6CsrGfk1urRW0zpZOH30M= +// @SCRIPT-SIGNATURE-V1: yk-r1.ES256.20251019T230159+08:00.MEQCIByk8UrJGAfSk3tNh4cr +// +0M5B6P+72yivwmFvGnWOzv4AiBAjVanUpEEU4hUxpP8I3B/xMEdm26eDe25/7VAaxEmKw==