Skip to content

Commit 4a95bff

Browse files
committed
feat: add openai and claude website test
1 parent 94c4737 commit 4a95bff

File tree

10 files changed

+206
-193
lines changed

10 files changed

+206
-193
lines changed

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ opt-level = "s"
1515

1616
[dependencies]
1717
proxrs = { path = "proxrs" }
18+
anyhow = "1.0.93"
1819
axum = "0.7.5"
1920
tower-http = { version = "0.5.2", features = ["fs"] }
2021
serde = { version = "1.0", features = ["derive"] }

conf/clash_release.yaml

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ proxy-groups:
7676
- JP
7777
- SG
7878
- US
79+
- OpenAI
80+
- Claude
7981
- name: Select
8082
type: select
8183
filter: ".*"
@@ -125,6 +127,20 @@ proxy-groups:
125127
tolerance: 500
126128
proxies: [ ]
127129
filter: "(?i)美|洛杉矶|芝加哥|西雅图|America|US|United.*?States"
130+
- name: OpenAI
131+
type: url-test
132+
url: http://www.google.com/generate_204
133+
interval: 600
134+
tolerance: 500
135+
proxies: [ PROXY ]
136+
filter: "(?i)OpenAI"
137+
- name: Claude
138+
type: url-test
139+
url: http://www.google.com/generate_204
140+
interval: 600
141+
tolerance: 500
142+
proxies: [ PROXY ]
143+
filter: "(?i)Claude"
128144
rules:
129145
- RULE-SET,ads,REJECT
130146
- RULE-SET,applications,DIRECT
@@ -134,8 +150,9 @@ rules:
134150
- RULE-SET,google-cn,DIRECT
135151
- RULE-SET,bilibili,DIRECT
136152
- RULE-SET,cn,DIRECT
137-
- RULE-SET,ai,PROXY
138-
- RULE-SET,proxy,PROXY
153+
- RULE-SET,claude,Claude
154+
- RULE-SET,ai,OpenAI
155+
- RULE-SET,youtube,PROXY
139156
- RULE-SET,telegramip,PROXY,no-resolve
140157
- RULE-SET,privateip,DIRECT,no-resolve
141158
- RULE-SET,cnip,DIRECT,no-resolve
@@ -221,16 +238,23 @@ rule-providers:
221238
behavior: domain
222239
format: mrs
223240
path: ./rules/ai.mrs
224-
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/clash-ruleset/ai.mrs"
241+
url: "https://github.com/ReaJason/Clash-Butler/raw/refs/heads/master/rules/ai/ai.mrs"
242+
interval: 86400
243+
244+
claude:
245+
type: http
246+
behavior: domain
247+
format: mrs
248+
path: ./rules/claude.mrs
249+
url: "https://github.com/ReaJason/Clash-Butler/raw/refs/heads/master/rules/claude/claude.mrs"
225250
interval: 86400
226-
# https://gitlab.com/lodepuly/vpn_tool/-/blob/master/Tool/Clash/Rule/AI.yaml
227251

228-
proxy:
252+
youtube:
229253
type: http
230254
behavior: domain
231255
format: mrs
232-
path: ./rules/proxy.mrs
233-
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/clash-ruleset/proxy.mrs"
256+
path: ./rules/youtube.mrs
257+
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/clash-ruleset/youtube.mrs"
234258
interval: 86400
235259

236260
cn:

conf/clash_test.yaml

Lines changed: 0 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,6 @@ proxy-groups:
3737
proxies: [ ]
3838
filter: ".*"
3939
rules:
40-
- RULE-SET,ads,REJECT
41-
- RULE-SET,applications,DIRECT
42-
- RULE-SET,private,DIRECT
43-
- RULE-SET,apple-cn,DIRECT
44-
- RULE-SET,games-cn,DIRECT
45-
- RULE-SET,google-cn,DIRECT
46-
- RULE-SET,bilibili,DIRECT
47-
- RULE-SET,cn,DIRECT
48-
- RULE-SET,ai,PROXY
49-
- RULE-SET,proxy,PROXY
50-
- RULE-SET,telegramip,PROXY,no-resolve
51-
- RULE-SET,privateip,DIRECT,no-resolve
52-
- RULE-SET,cnip,DIRECT,no-resolve
5340
- GEOIP,LAN,DIRECT,no-resolve
5441
- GEOIP,CN,DIRECT,no-resolve
5542
- MATCH,PROXY
@@ -61,117 +48,4 @@ rule-providers:
6148
format: mrs
6249
path: ./rules/fakeip-filter.mrs
6350
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/clash-ruleset/fakeip-filter.mrs"
64-
interval: 86400
65-
66-
ads:
67-
type: http
68-
behavior: domain
69-
format: mrs
70-
path: ./rules/ads.mrs
71-
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/clash-ruleset/ads.mrs"
72-
interval: 86400
73-
74-
applications:
75-
type: http
76-
behavior: classical
77-
format: text
78-
path: ./rules/applications.list
79-
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/clash-ruleset/applications.list"
80-
interval: 86400
81-
82-
private:
83-
type: http
84-
behavior: domain
85-
format: mrs
86-
path: ./rules/private.mrs
87-
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/clash-ruleset/private.mrs"
88-
interval: 86400
89-
90-
games-cn:
91-
type: http
92-
behavior: domain
93-
format: mrs
94-
path: ./rules/games-cn.mrs
95-
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/clash-ruleset/games-cn.mrs"
96-
interval: 86400
97-
98-
microsoft-cn:
99-
type: http
100-
behavior: domain
101-
format: mrs
102-
path: ./rules/microsoft-cn.mrs
103-
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/clash-ruleset/microsoft-cn.mrs"
104-
interval: 86400
105-
106-
apple-cn:
107-
type: http
108-
behavior: domain
109-
format: mrs
110-
path: ./rules/apple-cn.mrs
111-
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/clash-ruleset/apple-cn.mrs"
112-
interval: 86400
113-
114-
google-cn:
115-
type: http
116-
behavior: domain
117-
format: mrs
118-
path: ./rules/google-cn.mrs
119-
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/clash-ruleset/google-cn.mrs"
120-
interval: 86400
121-
122-
bilibili:
123-
type: http
124-
behavior: domain
125-
format: mrs
126-
path: ./rules/bilibili.mrs
127-
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/clash-ruleset/bilibili.mrs"
128-
interval: 86400
129-
130-
ai:
131-
type: http
132-
behavior: domain
133-
format: mrs
134-
path: ./rules/ai.mrs
135-
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/clash-ruleset/ai.mrs"
136-
interval: 86400
137-
# https://gitlab.com/lodepuly/vpn_tool/-/blob/master/Tool/Clash/Rule/AI.yaml
138-
139-
proxy:
140-
type: http
141-
behavior: domain
142-
format: mrs
143-
path: ./rules/proxy.mrs
144-
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/clash-ruleset/proxy.mrs"
145-
interval: 86400
146-
147-
cn:
148-
type: http
149-
behavior: domain
150-
format: mrs
151-
path: ./rules/cn.mrs
152-
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/clash-ruleset/cn.mrs"
153-
interval: 86400
154-
155-
telegramip:
156-
type: http
157-
behavior: ipcidr
158-
format: mrs
159-
path: ./rules/telegramip.mrs
160-
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/clash-ruleset/telegramip.mrs"
161-
interval: 86400
162-
163-
privateip:
164-
type: http
165-
behavior: ipcidr
166-
format: mrs
167-
path: ./rules/privateip.mrs
168-
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/clash-ruleset/privateip.mrs"
169-
interval: 86400
170-
171-
cnip:
172-
type: http
173-
behavior: ipcidr
174-
format: mrs
175-
path: ./rules/cnip.mrs
176-
url: "https://github.com/DustinWin/ruleset_geodata/releases/download/clash-ruleset/cnip.mrs"
17751
interval: 86400

conf/config.toml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@ fast_mode = false
66
# 支持本地地址(绝对地址)/User/xxx/xx.yml
77
# 支持单个订阅链接,ss://xxx
88
subs = [
9-
"https://sub.reajason.eu.org/clash.yaml",
10-
"https://s1.byte16.com/api/v1/client/subscribe?token=feba159f3478ff8936f52a43d88aae8b",
11-
"https://www.cwy-water.us.kg/api/v1/client/subscribe?token=daa0f9c43c5b7f91a08aee21dab0138c",
12-
"https://guanxi.us.kg/guanxi",
13-
"https://naiher.me/vdnYUg.txt",
9+
"https://raw.githubusercontent.com/ReaJason/Clash-Butler/refs/heads/master/clash.yaml"
1410
]
1511

1612
# 是否重命名节点,打开后会使用 geoip 等方式进行代理真实 IP 和地理地址查询
@@ -24,6 +20,9 @@ pools = [
2420
"https://raw.githubusercontent.com/Ruk1ng001/freeSub/main/clash.yaml"
2521
]
2622

23+
# 测试分组大小
24+
test_group_size = 50
25+
2726
# 连通性测试
2827
[connect_test]
2928
url = "http://www.google.com/generate_204"

proxrs/src/sub.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ impl SubManager {
250250
*name_counts.entry(name).or_insert(0) += 1;
251251
}
252252

253-
for proxy in proxies {
253+
for proxy in &mut *proxies {
254254
let name = proxy.get_name().to_string();
255255
if let Some(count) = name_counts.get(&name) {
256256
if count > &1 {
@@ -266,6 +266,9 @@ impl SubManager {
266266
}
267267
}
268268
}
269+
270+
// 以名称重新排序
271+
proxies.sort_by(|a, b| a.get_name().cmp(&b.get_name()));
269272
}
270273

271274
// 通过配置格式,获取 clash 配置文件内容
@@ -304,8 +307,14 @@ impl SubManager {
304307
.get_mut(Value::String("proxies".to_string()))
305308
.and_then(Value::as_sequence_mut)
306309
{
310+
let mut removed_default = false;
307311
for proxy in new_proxies {
308312
if regex.is_match(proxy.get_name()) {
313+
if !removed_default
314+
&& proxies.get(0).is_some_and(|p| p.as_str().unwrap().eq("PROXY")) {
315+
proxies.remove(0);
316+
removed_default = true;
317+
}
309318
proxies.push(Value::String(proxy.get_name().to_string()));
310319
}
311320
}
@@ -343,7 +352,7 @@ mod test {
343352
let mut proxies = SubManager::parse_from_path(
344353
"/Users/reajason/RustroverProjects/clash-butler/subs/0c1149d13476bbe3b62eecb7c9b895f4",
345354
)
346-
.unwrap();
355+
.unwrap();
347356
SubManager::unset_proxies_name(&mut proxies);
348357
let content = SubManager::get_clash_config_content(path.to_string(), &proxies).unwrap();
349358
println!("{}", content);
@@ -417,4 +426,19 @@ mod test {
417426
"/Users/reajason/RustroverProjects/clash-butler/subs/release/proxy.yaml".to_string();
418427
SubManager::save_proxies_into_clash_file(&proxies, release_clash_template_path, save_path);
419428
}
429+
430+
#[tokio::test]
431+
async fn test_rename() {
432+
let urls = vec![
433+
"/Users/reajason/RustroverProjects/clash-butler/clash.yaml"
434+
.to_string(),
435+
];
436+
let mut proxies = SubManager::get_proxies_from_urls(&urls).await;
437+
SubManager::rename_dup_proxies_name(&mut proxies);
438+
let release_clash_template_path =
439+
"/Users/reajason/RustroverProjects/clash-butler/conf/clash_release.yaml".to_string();
440+
let save_path =
441+
"/Users/reajason/RustroverProjects/clash-butler/clash1.yaml".to_string();
442+
SubManager::save_proxies_into_clash_file(&proxies, release_clash_template_path, save_path)
443+
}
420444
}

src/cgi_trace.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const CF_TRACE_URL: &str = "https://1.0.0.1/cdn-cgi/trace";
1818
const CF_CN_TRACE_URL: &str = "https://cf-ns.com/cdn-cgi/trace";
1919

2020
// IP 查询超时时间
21-
const TIMEOUT: Duration = Duration::from_millis(1000);
21+
const TIMEOUT: Duration = Duration::from_secs(5);
2222

2323
type IpBoxFuture<'a> = BoxFuture<'a, Result<(IpAddr, &'a str), Box<dyn std::error::Error>>>;
2424

0 commit comments

Comments
 (0)