mirror of
https://github.com/house-of-vanity/v2-uri-parser.git
synced 2025-12-15 22:47:52 +00:00
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:
@@ -265,3 +265,10 @@ pub struct RawData {
|
|||||||
pub server_method: Option<String>,
|
pub server_method: Option<String>,
|
||||||
pub username: Option<String>,
|
pub username: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
#[allow(non_snake_case)]
|
||||||
|
pub struct ConfigMetaData {
|
||||||
|
pub name: String,
|
||||||
|
pub protocol: String,
|
||||||
|
}
|
||||||
|
|||||||
12
src/main.rs
12
src/main.rs
@@ -28,9 +28,9 @@ fn main() {
|
|||||||
.value_parser(value_parser!(u16)),
|
.value_parser(value_parser!(u16)),
|
||||||
)
|
)
|
||||||
.arg(
|
.arg(
|
||||||
Arg::new("get_name")
|
Arg::new("get_metadata")
|
||||||
.long("get-name")
|
.long("get-metadata")
|
||||||
.help("Only print the config name")
|
.help("Only print config meta data")
|
||||||
.action(clap::ArgAction::SetTrue),
|
.action(clap::ArgAction::SetTrue),
|
||||||
)
|
)
|
||||||
.get_matches();
|
.get_matches();
|
||||||
@@ -38,10 +38,10 @@ fn main() {
|
|||||||
let uri = matches.get_one::<String>("uri").unwrap();
|
let uri = matches.get_one::<String>("uri").unwrap();
|
||||||
let socksport = matches.get_one::<u16>("socksport").copied();
|
let socksport = matches.get_one::<u16>("socksport").copied();
|
||||||
let httpport = matches.get_one::<u16>("httpport").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 {
|
if get_metadata {
|
||||||
print!("{}", parser::get_name(uri));
|
print!("{}", parser::get_metadata(uri));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use crate::config_models::{
|
use crate::config_models::{
|
||||||
self, GRPCSettings, KCPSettings, NonHeaderObject, Outbound, OutboundSettings, QuicSettings,
|
self, ConfigMetaData, GRPCSettings, KCPSettings, NonHeaderObject, Outbound, OutboundSettings,
|
||||||
RawData, RealitySettings, StreamSettings, TCPHeader, TCPSettings, TlsSettings, WsSettings,
|
QuicSettings, RawData, RealitySettings, StreamSettings, TCPHeader, TCPSettings, TlsSettings,
|
||||||
XHTTPSettings,
|
WsSettings, XHTTPSettings,
|
||||||
};
|
};
|
||||||
use crate::utils::{inbound_generator, parse_raw_json};
|
use crate::utils::{inbound_generator, parse_raw_json};
|
||||||
|
|
||||||
@@ -12,9 +12,14 @@ mod uri_identifier;
|
|||||||
mod vless;
|
mod vless;
|
||||||
mod vmess;
|
mod vmess;
|
||||||
|
|
||||||
pub fn get_name(uri: &str) -> String {
|
pub fn get_metadata(uri: &str) -> String {
|
||||||
let (_, data, _) = get_uri_data(uri);
|
let (protocol, data, _) = get_uri_data(uri);
|
||||||
return data.remarks;
|
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 {
|
pub fn create_json_config(uri: &str, socks_port: Option<u16>, http_port: Option<u16>) -> String {
|
||||||
|
|||||||
Reference in New Issue
Block a user