Skip to main content

threexui_rs/models/
xray.rs

1use serde::Deserialize;
2
3#[derive(Debug, Clone, Deserialize)]
4#[serde(rename_all = "camelCase")]
5pub struct XraySetting {
6    pub xray_setting: serde_json::Value,
7    pub inbound_tags: serde_json::Value,
8    pub outbound_test_url: String,
9}
10
11#[derive(Debug, Clone, Deserialize)]
12pub struct OutboundTraffic {
13    pub id: i64,
14    pub tag: String,
15    pub up: i64,
16    pub down: i64,
17    pub total: i64,
18}
19
20#[derive(Debug, Clone)]
21pub enum WarpAction {
22    Data,
23    Delete,
24    Config,
25    Register {
26        private_key: String,
27        public_key: String,
28    },
29    SetLicense(String),
30}
31
32impl WarpAction {
33    pub fn action_str(&self) -> &str {
34        match self {
35            WarpAction::Data => "data",
36            WarpAction::Delete => "del",
37            WarpAction::Config => "config",
38            WarpAction::Register { .. } => "reg",
39            WarpAction::SetLicense(_) => "license",
40        }
41    }
42}
43
44#[derive(Debug, Clone)]
45pub enum NordAction {
46    Countries,
47    Servers { country_id: String },
48    Register { token: String },
49    SetKey(String),
50    Data,
51    Delete,
52}
53
54impl NordAction {
55    pub fn action_str(&self) -> &str {
56        match self {
57            NordAction::Countries => "countries",
58            NordAction::Servers { .. } => "servers",
59            NordAction::Register { .. } => "reg",
60            NordAction::SetKey(_) => "setKey",
61            NordAction::Data => "data",
62            NordAction::Delete => "del",
63        }
64    }
65}
66
67#[cfg(test)]
68mod tests {
69    use super::*;
70
71    #[test]
72    fn warp_action_str() {
73        assert_eq!(WarpAction::Data.action_str(), "data");
74        assert_eq!(WarpAction::Delete.action_str(), "del");
75        assert_eq!(
76            WarpAction::Register {
77                private_key: "a".into(),
78                public_key: "b".into()
79            }
80            .action_str(),
81            "reg"
82        );
83    }
84
85    #[test]
86    fn nord_action_str() {
87        assert_eq!(NordAction::Countries.action_str(), "countries");
88        assert_eq!(
89            NordAction::Servers {
90                country_id: "1".into()
91            }
92            .action_str(),
93            "servers"
94        );
95    }
96}