fix: correct inaccurate Gemini unlock test

This commit is contained in:
wonfen 2026-03-19 03:00:50 +08:00
parent 6685e7a1bd
commit c6a7a2fb52
No known key found for this signature in database
GPG Key ID: CEAFD6C73AB2001F
2 changed files with 35 additions and 47 deletions

View File

@ -8,6 +8,7 @@
- 切换配置文件偶尔失败的问题
- 修复节点或模式切换出现极大延迟的回归问题
- 修复代理关闭的情况下,网站测试依然会走代理的问题
- 修复 Gemini 解锁测试不准确的情况
<details>
<summary><strong> ✨ 新增功能 </strong></summary>

View File

@ -1,61 +1,48 @@
use regex::Regex;
use reqwest::Client;
use clash_verge_logging::{Type, logging};
use super::UnlockItem;
use super::utils::{country_code_to_emoji, get_local_date_string};
const BLOCKED_CODES: [&str; 9] = ["CHN", "RUS", "BLR", "CUB", "IRN", "PRK", "SYR", "HKG", "MAC"];
const REGION_MARKER: &str = ",2,1,200,\"";
pub(super) async fn check_gemini(client: &Client) -> UnlockItem {
let url = "https://gemini.google.com";
let failed = || UnlockItem {
name: "Gemini".to_string(),
status: "Failed".to_string(),
region: None,
check_time: Some(get_local_date_string()),
};
match client.get(url).send().await {
Ok(response) => {
if let Ok(body) = response.text().await {
let is_ok = body.contains("45631641,null,true");
let status = if is_ok { "Yes" } else { "No" };
let response = match client.get(url).send().await {
Ok(r) => r,
Err(_) => return failed(),
};
let body = match response.text().await {
Ok(b) => b,
Err(_) => return failed(),
};
let re = match Regex::new(r#",2,1,200,"([A-Z]{3})""#) {
Ok(re) => re,
Err(e) => {
logging!(error, Type::Network, "Failed to compile Gemini regex: {}", e);
return UnlockItem {
name: "Gemini".to_string(),
status: "Failed".to_string(),
region: None,
check_time: Some(get_local_date_string()),
};
}
};
let country_code = body
.find(REGION_MARKER)
.and_then(|i| {
let start = i + REGION_MARKER.len();
body.get(start..start + 3)
})
.filter(|s| s.bytes().all(|b| b.is_ascii_uppercase()));
let region = re.captures(&body).and_then(|caps| {
caps.get(1).map(|m| {
let country_code = m.as_str();
let emoji = country_code_to_emoji(country_code);
format!("{emoji}{country_code}")
})
});
UnlockItem {
name: "Gemini".to_string(),
status: status.to_string(),
region,
check_time: Some(get_local_date_string()),
}
} else {
UnlockItem {
name: "Gemini".to_string(),
status: "Failed".to_string(),
region: None,
check_time: Some(get_local_date_string()),
}
match country_code {
Some(code) => {
let emoji = country_code_to_emoji(code);
let status = if BLOCKED_CODES.contains(&code) { "No" } else { "Yes" };
UnlockItem {
name: "Gemini".to_string(),
status: status.to_string(),
region: Some(format!("{emoji}{code}")),
check_time: Some(get_local_date_string()),
}
}
Err(_) => UnlockItem {
name: "Gemini".to_string(),
status: "Failed".to_string(),
region: None,
check_time: Some(get_local_date_string()),
},
None => failed(),
}
}