feat: udpate connect.rs
This commit is contained in:
@@ -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<String> {
|
||||
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<String> {
|
||||
let auth_token = get_pac_auth_token()?;
|
||||
let url = format!(
|
||||
@@ -214,5 +225,5 @@ fn get_pac_auth_token() -> XResult<String> {
|
||||
))
|
||||
}
|
||||
|
||||
// @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==
|
||||
|
||||
Reference in New Issue
Block a user