feat: get config metadata

This will replace --get-name add provide both name and protocol in a
single json object
This commit is contained in:
Keivan-sf
2025-07-28 18:09:14 +03:30
parent 82a5942af7
commit 1dfb45412f
3 changed files with 24 additions and 12 deletions

View File

@@ -265,3 +265,10 @@ pub struct RawData {
pub server_method: Option<String>,
pub username: Option<String>,
}
#[derive(Serialize, Deserialize)]
#[allow(non_snake_case)]
pub struct ConfigMetaData {
pub name: String,
pub protocol: String,
}

View File

@@ -28,9 +28,9 @@ fn main() {
.value_parser(value_parser!(u16)),
)
.arg(
Arg::new("get_name")
.long("get-name")
.help("Only print the config name")
Arg::new("get_metadata")
.long("get-metadata")
.help("Only print config meta data")
.action(clap::ArgAction::SetTrue),
)
.get_matches();
@@ -38,10 +38,10 @@ fn main() {
let uri = matches.get_one::<String>("uri").unwrap();
let socksport = matches.get_one::<u16>("socksport").copied();
let httpport = matches.get_one::<u16>("httpport").copied();
let get_name = matches.get_flag("get_name");
let get_metadata = matches.get_flag("get_metadata");
if get_name {
print!("{}", parser::get_name(uri));
if get_metadata {
print!("{}", parser::get_metadata(uri));
return;
}

View File

@@ -1,7 +1,7 @@
use crate::config_models::{
self, GRPCSettings, KCPSettings, NonHeaderObject, Outbound, OutboundSettings, QuicSettings,
RawData, RealitySettings, StreamSettings, TCPHeader, TCPSettings, TlsSettings, WsSettings,
XHTTPSettings,
self, ConfigMetaData, GRPCSettings, KCPSettings, NonHeaderObject, Outbound, OutboundSettings,
QuicSettings, RawData, RealitySettings, StreamSettings, TCPHeader, TCPSettings, TlsSettings,
WsSettings, XHTTPSettings,
};
use crate::utils::{inbound_generator, parse_raw_json};
@@ -12,9 +12,14 @@ mod uri_identifier;
mod vless;
mod vmess;
pub fn get_name(uri: &str) -> String {
let (_, data, _) = get_uri_data(uri);
return data.remarks;
pub fn get_metadata(uri: &str) -> String {
let (protocol, data, _) = get_uri_data(uri);
let meta_data = ConfigMetaData {
name: data.remarks,
protocol,
};
let serialized = serde_json::to_string(&meta_data).unwrap();
return serialized;
}
pub fn create_json_config(uri: &str, socks_port: Option<u16>, http_port: Option<u16>) -> String {