Skip to content

Commit 191c27f

Browse files
authored
参考cm
2.7
2 parents 801d707 + a5cfeb0 commit 191c27f

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

明文源吗

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1867,12 +1867,6 @@
18671867
if (!user) user = at;
18681868

18691869
const url = new URL(request.url);
1870-
1871-
if (url.protocol === 'https:') {
1872-
const httpUrl = 'http://' + url.host + url.pathname + url.search;
1873-
return Response.redirect(httpUrl, 302);
1874-
}
1875-
18761870
// 优先检查Cookie中的语言设置
18771871
const cookieHeader = request.headers.get('Cookie') || '';
18781872
let langFromCookie = null;
@@ -4023,6 +4017,18 @@
40234017
});
40244018
}
40254019

4020+
function ipToHex(ip) {
4021+
const parts = ip.split('.');
4022+
if (parts.length !== 4) return null;
4023+
let hex = '';
4024+
for (let i = 0; i < 4; i++) {
4025+
const num = parseInt(parts[i]);
4026+
if (isNaN(num) || num < 0 || num > 255) return null;
4027+
hex += num.toString(16).padStart(2, '0');
4028+
}
4029+
return hex;
4030+
}
4031+
40264032
const coloMap = {
40274033
'SJC': '圣何塞', 'LAX': '洛杉矶', 'SEA': '西雅图', 'SFO': '旧金山', 'DFW': '达拉斯',
40284034
'ORD': '芝加哥', 'IAD': '华盛顿', 'ATL': '亚特兰大', 'MIA': '迈阿密', 'DEN': '丹佛',
@@ -4098,11 +4104,11 @@
40984104
}
40994105

41004106
const cleanHost = host.replace(/^\\[|\\]$/g, '');
4101-
const isIPv6 = cleanHost.includes(':');
4102-
const hostPart = isIPv6 ? ('[' + cleanHost + ']') : cleanHost;
4103-
testUrl = 'http://' + hostPart + ':80/cdn-cgi/trace';
4107+
const hexIP = ipToHex(cleanHost);
4108+
const testDomain = hexIP ? (hexIP + '.nip.lfree.org') : (cleanHost + '.nip.lfree.org');
4109+
testUrl = 'https://' + testDomain + ':' + port + '/';
41044110

4105-
console.log('[LatencyTest] Testing:', testUrl, 'Original:', host + ':' + port);
4111+
console.log('[LatencyTest] Testing:', testUrl, 'Original:', host + ':' + port, 'HexIP:', hexIP);
41064112

41074113
const firstStart = Date.now();
41084114
const response1 = await fetch(testUrl, {
@@ -4118,9 +4124,9 @@
41184124
try {
41194125
const text = await response1.text();
41204126
console.log('[LatencyTest] Response body:', text.substring(0, 200));
4121-
const coloMatch = text.match(/colo=([A-Z]+)/);
4122-
if (coloMatch) {
4123-
colo = coloMatch[1];
4127+
const data = JSON.parse(text);
4128+
if (data.colo) {
4129+
colo = data.colo;
41244130
}
41254131
} catch (e) {
41264132
console.log('[LatencyTest] Parse error:', e.message);

0 commit comments

Comments
 (0)