mirror of
https://github.com/clash-verge-rev/clash-verge-rev.git
synced 2026-04-18 16:30:32 +08:00
fix: correct inaccurate Gemini unlock test
This commit is contained in:
parent
6685e7a1bd
commit
c6a7a2fb52
@ -8,6 +8,7 @@
|
|||||||
- 切换配置文件偶尔失败的问题
|
- 切换配置文件偶尔失败的问题
|
||||||
- 修复节点或模式切换出现极大延迟的回归问题
|
- 修复节点或模式切换出现极大延迟的回归问题
|
||||||
- 修复代理关闭的情况下,网站测试依然会走代理的问题
|
- 修复代理关闭的情况下,网站测试依然会走代理的问题
|
||||||
|
- 修复 Gemini 解锁测试不准确的情况
|
||||||
|
|
||||||
<details>
|
<details>
|
||||||
<summary><strong> ✨ 新增功能 </strong></summary>
|
<summary><strong> ✨ 新增功能 </strong></summary>
|
||||||
|
|||||||
@ -1,61 +1,48 @@
|
|||||||
use regex::Regex;
|
|
||||||
use reqwest::Client;
|
use reqwest::Client;
|
||||||
|
|
||||||
use clash_verge_logging::{Type, logging};
|
|
||||||
|
|
||||||
use super::UnlockItem;
|
use super::UnlockItem;
|
||||||
use super::utils::{country_code_to_emoji, get_local_date_string};
|
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 {
|
pub(super) async fn check_gemini(client: &Client) -> UnlockItem {
|
||||||
let url = "https://gemini.google.com";
|
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 {
|
let response = match client.get(url).send().await {
|
||||||
Ok(response) => {
|
Ok(r) => r,
|
||||||
if let Ok(body) = response.text().await {
|
Err(_) => return failed(),
|
||||||
let is_ok = body.contains("45631641,null,true");
|
};
|
||||||
let status = if is_ok { "Yes" } else { "No" };
|
let body = match response.text().await {
|
||||||
|
Ok(b) => b,
|
||||||
|
Err(_) => return failed(),
|
||||||
|
};
|
||||||
|
|
||||||
let re = match Regex::new(r#",2,1,200,"([A-Z]{3})""#) {
|
let country_code = body
|
||||||
Ok(re) => re,
|
.find(REGION_MARKER)
|
||||||
Err(e) => {
|
.and_then(|i| {
|
||||||
logging!(error, Type::Network, "Failed to compile Gemini regex: {}", e);
|
let start = i + REGION_MARKER.len();
|
||||||
return UnlockItem {
|
body.get(start..start + 3)
|
||||||
name: "Gemini".to_string(),
|
})
|
||||||
status: "Failed".to_string(),
|
.filter(|s| s.bytes().all(|b| b.is_ascii_uppercase()));
|
||||||
region: None,
|
|
||||||
check_time: Some(get_local_date_string()),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let region = re.captures(&body).and_then(|caps| {
|
match country_code {
|
||||||
caps.get(1).map(|m| {
|
Some(code) => {
|
||||||
let country_code = m.as_str();
|
let emoji = country_code_to_emoji(code);
|
||||||
let emoji = country_code_to_emoji(country_code);
|
let status = if BLOCKED_CODES.contains(&code) { "No" } else { "Yes" };
|
||||||
format!("{emoji}{country_code}")
|
UnlockItem {
|
||||||
})
|
name: "Gemini".to_string(),
|
||||||
});
|
status: status.to_string(),
|
||||||
|
region: Some(format!("{emoji}{code}")),
|
||||||
UnlockItem {
|
check_time: Some(get_local_date_string()),
|
||||||
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()),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(_) => UnlockItem {
|
None => failed(),
|
||||||
name: "Gemini".to_string(),
|
|
||||||
status: "Failed".to_string(),
|
|
||||||
region: None,
|
|
||||||
check_time: Some(get_local_date_string()),
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user