libsubconverter/generator/config/vmess.rs
1//! VMess link construction utilities
2//!
3//! This module provides functionality for building VMess links.
4
5use serde_json::json;
6
7use crate::utils::base64::base64_encode;
8
9/// Constructs a VMess link from the provided parameters
10///
11/// # Arguments
12///
13/// * `remarks` - Remarks (name) for the VMess link
14/// * `add` - Server address
15/// * `port` - Server port
16/// * `type_str` - Connection type (e.g., "tcp", "ws")
17/// * `id` - UUID
18/// * `aid` - AlterID
19/// * `net` - Network protocol
20/// * `path` - WebSocket path or other path-like parameter
21/// * `host` - Host header
22/// * `tls` - TLS setting
23///
24/// # Returns
25///
26/// A VMess URI string
27pub fn vmess_link_construct(
28 remarks: &str,
29 add: &str,
30 port: &str,
31 type_str: &str,
32 id: &str,
33 aid: &str,
34 net: &str,
35 path: &str,
36 host: &str,
37 tls: &str,
38) -> String {
39 // Create the JSON object
40 let json_obj = json!({
41 "v": "2",
42 "ps": remarks,
43 "add": add,
44 "port": port,
45 "id": id,
46 "aid": aid,
47 "net": net,
48 "type": type_str,
49 "host": host,
50 "path": path,
51 "tls": tls
52 });
53
54 // Convert to string
55 let json_string = serde_json::to_string(&json_obj).unwrap_or_default();
56
57 // Encode to Base64
58 let encoded = base64_encode(&json_string);
59
60 // Return vmess:// URL
61 format!("vmess://{}", encoded)
62}