mirror of
https://github.com/clash-verge-rev/clash-verge-rev
synced 2025-05-05 06:53:44 +08:00
feat: add IP info request retry mechanism to reduce network errors
This commit is contained in:
parent
541b78ba6f
commit
4f15bdf74d
@ -21,6 +21,7 @@
|
|||||||
#### 优化了:
|
#### 优化了:
|
||||||
- 系统代理 Bypass 设置
|
- 系统代理 Bypass 设置
|
||||||
- Windows 下使用 Startup 文件夹的方式实现开机自启,解决管理员模式下开机自启的各种问题
|
- Windows 下使用 Startup 文件夹的方式实现开机自启,解决管理员模式下开机自启的各种问题
|
||||||
|
- 增加 IP 信息请求重试机制,减少 Network Error 发生的情况
|
||||||
|
|
||||||
## v2.2.3
|
## v2.2.3
|
||||||
|
|
||||||
|
@ -321,19 +321,40 @@ export const gc = async () => {
|
|||||||
|
|
||||||
// Get current IP and geolocation information
|
// Get current IP and geolocation information
|
||||||
export const getIpInfo = async () => {
|
export const getIpInfo = async () => {
|
||||||
// 使用axios直接请求IP.sb的API,不通过clash代理
|
// 添加重试机制
|
||||||
const response = await axios.get("https://api.ip.sb/geoip");
|
const maxRetries = 3;
|
||||||
return response.data as {
|
const retryDelay = 1500;
|
||||||
ip: string;
|
const timeout = 5000;
|
||||||
country_code: string;
|
|
||||||
country: string;
|
let lastError;
|
||||||
region: string;
|
|
||||||
city: string;
|
for (let attempt = 0; attempt < maxRetries; attempt++) {
|
||||||
organization: string;
|
try {
|
||||||
asn: number;
|
// 使用axios直接请求IP.sb的API,不通过clash代理
|
||||||
asn_organization: string;
|
const response = await axios.get("https://api.ip.sb/geoip", { timeout });
|
||||||
longitude: number;
|
return response.data as {
|
||||||
latitude: number;
|
ip: string;
|
||||||
timezone: string;
|
country_code: string;
|
||||||
};
|
country: string;
|
||||||
|
region: string;
|
||||||
|
city: string;
|
||||||
|
organization: string;
|
||||||
|
asn: number;
|
||||||
|
asn_organization: string;
|
||||||
|
longitude: number;
|
||||||
|
latitude: number;
|
||||||
|
timezone: string;
|
||||||
|
};
|
||||||
|
} catch (error) {
|
||||||
|
console.log(`获取IP信息失败,尝试 ${attempt + 1}/${maxRetries}`, error);
|
||||||
|
lastError = error;
|
||||||
|
|
||||||
|
// 如果不是最后一次尝试,则等待后重试
|
||||||
|
if (attempt < maxRetries - 1) {
|
||||||
|
await new Promise(resolve => setTimeout(resolve, retryDelay));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw lastError;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user