Skip to content

Commit c4a4822

Browse files
author
cht
committed
序列化
1 parent 3bdea9a commit c4a4822

5 files changed

Lines changed: 33 additions & 60 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ crossterm = "0.20"
1515
reqwest = { version = "0.11", default-features = false, features = ["json","rustls-tls"] }
1616
base64 = "0.13.0"
1717
serde_json = "1.0"
18+
serde = { version = "1.0", features = ["derive"] }
1819
urlencoding = "2.1.0"
1920
unicode-width = "0.1"
2021
tokio = { version = "1", features = ["full"] }

src/spider.rs

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//extern crate base64;
22
use reqwest::Result;
33
use serde_json::Value;
4+
use serde::{Deserialize, Serialize};
45
pub fn ascii_to_char(code: u8) -> char {
56
std::char::from_u32(code as u32).unwrap_or('_')
67
}
@@ -55,7 +56,7 @@ enum Tcp {
5556
Ss,
5657
V2,
5758
}
58-
#[derive(Clone)]
59+
#[derive(Clone,Serialize, Deserialize)]
5960
pub struct Information {
6061
pub func: String,
6162
pub urls: String,
@@ -94,26 +95,26 @@ impl Information {
9495
}}
9596
}}],
9697
\"outbounds\":[{{
97-
\"protocol\":{},
98+
\"protocol\":\"{}\",
9899
\"sendThrough\": \"0.0.0.0\",
99100
\"settings\":{{
100101
\"vnext\": [{{
101-
\"address\": {},
102+
\"address\": \"{}\",
102103
\"port\":{},
103104
\"users\":[{{
104-
\"alterId\": {},
105-
\"id\":{}
105+
\"alterId\": \"{}\",
106+
\"id\":\"{}\"
106107
}}]
107108
}}]
108109
}},
109110
\"streamSettings\":{{
110111
\"dsSettings\": {{
111-
\"path\": {}
112+
\"path\": \"{}\"
112113
}},
113114
\"httpSettings\":{{
114115
\"host\": [
115116
],
116-
\"path\":{}
117+
\"path\":\"{}\"
117118
}},
118119
\"kcpSettings\": {{
119120
\"congestion\": false,
@@ -127,7 +128,7 @@ impl Information {
127128
\"uplinkCapacity\": 5,
128129
\"writeBufferSize\": 1
129130
}},
130-
\"network\": {},
131+
\"network\": \"{}\",
131132
\"quicSettings\":{{
132133
\"header\": {{
133134
\"type\":\"none\"
@@ -168,7 +169,7 @@ impl Information {
168169
\"wsSettings\" :{{
169170
\"headers\" :{{
170171
}},
171-
\"path\":{}
172+
\"path\":\"{}\"
172173
}},
173174
\"xtlsSettings\":{{
174175
\"allowInsecure\":true,
@@ -200,8 +201,8 @@ impl Information {
200201
}}",
201202
self.func,
202203
self.add,
203-
remove_quotation(self.port.clone()),
204-
remove_quotation(self.aid.clone()),
204+
self.port.clone(),
205+
self.aid.clone(),
205206
self.id,
206207
self.path,
207208
self.path,
@@ -329,12 +330,12 @@ impl Information {
329330
\"settings\": {{
330331
\"servers\" :[
331332
{{
332-
\"address\":{},
333+
\"address\":\"{}\",
333334
\"email\": \"\",
334335
\"level\": 0,
335-
\"method\": {},
336+
\"method\": \"{}\",
336337
\"ota\":false,
337-
\"password\":{},
338+
\"password\":\"{}\",
338339
\"port\":{}
339340
}}
340341
]
@@ -424,7 +425,7 @@ impl Information {
424425
self.add,
425426
self.net,
426427
self.id,
427-
remove_quotation(self.port.clone())
428+
self.port.clone()
428429
)
429430
}
430431
}
@@ -433,12 +434,12 @@ impl Information {
433434
if self.func == *"\"vmess\"" {
434435
temp.push_str(&format!(
435436
"vmess://{}:{}-{}@{}:{}/#{}",
436-
&remove_quotation(self.net.clone()),
437-
&remove_quotation(self.id.clone()),
438-
&remove_quotation(self.aid.clone()),
439-
&remove_quotation(self.add.clone()),
440-
&remove_quotation(self.port.clone()),
441-
&remove_quotation(self.ps.clone())
437+
self.net.clone(),
438+
self.id.clone(),
439+
self.aid.clone(),
440+
self.add.clone(),
441+
self.port.clone(),
442+
self.ps.clone()
442443
))
443444
} else {
444445
temp = self.urls.clone();
@@ -448,8 +449,8 @@ impl Information {
448449
pub fn get_the_json_node(&self) -> String {
449450
format!(
450451
"{{
452+
\"urls\":\"{}\",
451453
\"func\":{},
452-
\"url\":\"{}\",
453454
\"add\":{},
454455
\"aid\":{},
455456
\"host\":{},
@@ -459,10 +460,12 @@ impl Information {
459460
\"port\":{},
460461
\"ps\":{},
461462
\"tls\":{},
462-
\"type\":{}
463+
\"typpe\":{}
463464
}},\n",
464-
self.func,
465+
465466
self.urls,
467+
468+
self.func,
466469
self.add,
467470
self.aid,
468471
self.host,

src/state.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::app::App;
22
use crate::informations::appbar::AppBar;
3-
use crate::spider;
3+
//use crate::spider;
44
use crate::subscribe::appsub::AppSub;
55
use crate::utils;
66
use std::io;
@@ -31,7 +31,7 @@ pub async fn run_app(terminal: &mut Terminal<MyBackend>) -> io::Result<()> {
3131
.map(|ainformation| {
3232
ainformation
3333
.iter()
34-
.map(|message| spider::remove_quotation(message.ps.clone()))
34+
.map(|message| message.ps.clone())
3535
.collect()
3636
})
3737
.collect();

src/subscribe/state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub(super) async fn subscribe_state(app: &mut AppSub) -> io::Result<IFEXIT> {
3131
subs.push(
3232
ainformation
3333
.iter()
34-
.map(|ainfor| spider::remove_quotation(ainfor.ps.clone()))
34+
.map(|ainfor| ainfor.ps.clone())
3535
.collect(),
3636
);
3737
information.push(ainformation);

src/utils.rs

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -92,37 +92,6 @@ pub fn start() -> Vec<Vec<Information>> {
9292
"[]".to_string()
9393
}
9494
};
95-
let mut informations = Vec::new();
96-
let v: Value = serde_json::from_str(messages.as_str()).unwrap();
97-
let mut index = 0;
98-
while v[index] != Value::Null {
99-
let mut index2 = 0;
100-
let w = v[index].clone();
101-
let mut information = Vec::new();
102-
while w[index2] != Value::Null {
103-
let the_url = w[index2]["url"].to_string();
104-
let length = the_url.len();
105-
let instore = &the_url[1..length - 1];
106-
information.push(Information {
107-
urls: instore.to_string(),
108-
func: w[index2]["func"].to_string(),
109-
add: w[index2]["add"].to_string(),
110-
aid: w[index2]["aid"].to_string(),
111-
host: w[index2]["host"].to_string(),
112-
id: w[index2]["id"].to_string(),
113-
net: w[index2]["net"].to_string(),
114-
path: w[index2]["path"].to_string(),
115-
port: w[index2]["port"].to_string(),
116-
ps: w[index2]["ps"].to_string(),
117-
tls: w[index2]["tls"].to_string(),
118-
typpe: w[index2]["type"].to_string(),
119-
});
120-
index2 += 1;
121-
}
122-
informations.push(information);
123-
//let names = v[index]["ps"].to_string();
124-
//start.add_item(remove_quotation(names), url);
125-
index += 1;
126-
}
127-
informations
95+
serde_json::from_str(messages.as_str()).unwrap()
96+
12897
}

0 commit comments

Comments
 (0)