Cargo format

This commit is contained in:
AB
2025-12-01 01:44:40 +02:00
parent 113c8254ab
commit 1249d15aad
7 changed files with 25 additions and 16 deletions

View File

@@ -1,4 +1,4 @@
use clap::{value_parser, Arg, Command};
use clap::{Arg, Command, value_parser};
pub mod config_models;
mod parser;
pub mod utils;
@@ -54,7 +54,10 @@ async fn main() {
let httpport = matches.get_one::<u16>("httpport").copied();
let get_metadata = matches.get_flag("get_metadata");
let run_mode = matches.get_flag("run");
let xray_binary = matches.get_one::<String>("xray_binary").map(|s| s.as_str()).unwrap_or("xray-core");
let xray_binary = matches
.get_one::<String>("xray_binary")
.map(|s| s.as_str())
.unwrap_or("xray-core");
if get_metadata {
print!("{}", parser::get_metadata(uri));

View File

@@ -5,7 +5,7 @@ use crate::{
parser::shadow_socks::models,
utils::{url_decode, url_decode_str},
};
use base64::{engine::general_purpose, Engine};
use base64::{Engine, engine::general_purpose};
pub fn get_data(uri: &str) -> RawData {
let data = uri.split_once("ss://").unwrap().1;

View File

@@ -5,7 +5,7 @@ use crate::{
parser::socks::models,
utils::{url_decode, url_decode_str},
};
use base64::{engine::general_purpose, Engine};
use base64::{Engine, engine::general_purpose};
pub fn get_data(uri: &str) -> RawData {
let data = uri.split_once("://").unwrap().1;

View File

@@ -34,7 +34,9 @@ mod tests {
use super::*;
#[test]
fn return_none_for_invalid_uri() {
let protocol = get_uri_protocol("123-vless://3d1c3f04-729d-59d3-bdb6-3f3f4352e173@root.ii.one:2083?security=reality&sni=www.spamhaus.org&fp=safari&pbk=7xhH4b_VkliBxGulljcyPOH-bYUA2dl-XAdZAsfhk04&sid=6ba85179e30d4fc2&type=tcp&flow=xtls-rprx-vision#Ha-ac");
let protocol = get_uri_protocol(
"123-vless://3d1c3f04-729d-59d3-bdb6-3f3f4352e173@root.ii.one:2083?security=reality&sni=www.spamhaus.org&fp=safari&pbk=7xhH4b_VkliBxGulljcyPOH-bYUA2dl-XAdZAsfhk04&sid=6ba85179e30d4fc2&type=tcp&flow=xtls-rprx-vision#Ha-ac",
);
assert!(matches!(protocol, None));
}
#[test]

View File

@@ -41,7 +41,7 @@ pub fn get_data(uri: &str) -> RawData {
extra: url_decode(get_parameter_value(&query, "extra")),
allowInsecure: get_parameter_value(&query, "allowInsecure"),
server_method: None,
username:None,
username: None,
};
}

View File

@@ -1,7 +1,7 @@
use crate::config_models::RawData;
use crate::parser::vmess::models::VmessAddress;
use crate::utils::{get_parameter_value, url_decode, url_decode_str};
use base64::{engine::general_purpose, Engine};
use base64::{Engine, engine::general_purpose};
use http::Uri;
use serde_json::Value;

View File

@@ -1,7 +1,7 @@
use std::process::Stdio;
use tokio::process::{Child, Command};
use tempfile::NamedTempFile;
use std::io::Write;
use std::process::Stdio;
use tempfile::NamedTempFile;
use tokio::process::{Child, Command};
pub struct XrayRunner {
process: Option<Child>,
@@ -16,7 +16,11 @@ impl XrayRunner {
}
}
pub async fn start(&mut self, config_json: &str, xray_binary: &str) -> Result<(), Box<dyn std::error::Error>> {
pub async fn start(
&mut self,
config_json: &str,
xray_binary: &str,
) -> Result<(), Box<dyn std::error::Error>> {
// Create temporary config file with .json extension
let mut temp_file = NamedTempFile::with_suffix(".json")?;
temp_file.write_all(config_json.as_bytes())?;
@@ -27,10 +31,10 @@ impl XrayRunner {
// Start xray-core process
let mut cmd = Command::new(xray_binary);
cmd.arg("-config")
.arg(&config_path)
.stdin(Stdio::null())
.stdout(Stdio::inherit())
.stderr(Stdio::inherit());
.arg(&config_path)
.stdin(Stdio::null())
.stdout(Stdio::inherit())
.stderr(Stdio::inherit());
let child = cmd.spawn()?;
@@ -89,9 +93,9 @@ impl Drop for XrayRunner {
pub async fn wait_for_shutdown_signal() {
#[cfg(unix)]
{
use futures::stream::StreamExt;
use signal_hook::consts::signal::*;
use signal_hook_tokio::Signals;
use futures::stream::StreamExt;
let mut signals = Signals::new(&[SIGINT, SIGTERM]).expect("Failed to create signals");