Skip to content

Commit 9fb0650

Browse files
committed
feat: 修复随机优选时遗漏运营商信息,优化订阅转换URL构建
1 parent 79ab969 commit 9fb0650

2 files changed

Lines changed: 46 additions & 11 deletions

File tree

CHANGELOG

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
## [2.1.20260508190728] - 2026-05-08 19:07:28
22

3+
### Debug
4+
5+
- 修复 **随机优选** 时,订阅转换后遗漏运营商信息,导致无法生成对应运营商优选IP的问题。
6+
37
### Change
48

5-
- 订阅转换时将提交临时 `TOKEN` 用于转换,避免真实订阅地址泄露。
9+
- 优化 订阅转换时将提交临时 `TOKEN` 用于转换,避免真实订阅地址泄露。
610

711
## [2.1.20260508041513] - 2026-05-08 04:15:13
812

_worker.js

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ export default {
429429
}
430430
}).filter(item => item !== null).join('\n');
431431
} else { // 订阅转换
432-
const 订阅转换URL = `${config_JSON.订阅转换配置.SUBAPI}/sub?target=${订阅类型}&url=${encodeURIComponent(url.protocol + '//' + url.host + '/sub?target=mixed&token=' + 今日订阅转换后端专属TOKEN + (url.searchParams.has('sub') && url.searchParams.get('sub') != '' ? `&sub=${url.searchParams.get('sub')}` : ''))}&config=${encodeURIComponent(config_JSON.订阅转换配置.SUBCONFIG)}&emoji=${config_JSON.订阅转换配置.SUBEMOJI}&scv=${config_JSON.跳过证书验证}`;
432+
const 订阅转换URL = `${config_JSON.订阅转换配置.SUBAPI}/sub?target=${订阅类型}&url=${encodeURIComponent(url.protocol + '//' + url.host + '/sub?target=mixed&token=' + 今日订阅转换后端专属TOKEN + '&asOrg=' + 识别运营商(request) + (url.searchParams.has('sub') && url.searchParams.get('sub') != '' ? `&sub=${url.searchParams.get('sub')}` : ''))}&config=${encodeURIComponent(config_JSON.订阅转换配置.SUBCONFIG)}&emoji=${config_JSON.订阅转换配置.SUBEMOJI}&scv=${config_JSON.跳过证书验证}`;
433433
try {
434434
const response = await fetch(订阅转换URL, { headers: { 'User-Agent': 'Subconverter for ' + 订阅类型 + ' edge' + 'tunnel (https://github.com/cmliu/edge' + 'tunnel)' } });
435435
if (response.ok) {
@@ -4677,17 +4677,48 @@ async function 读取config_JSON(env, hostname, userID, UA = "Mozilla/5.0", 重
46774677
return config_JSON;
46784678
}
46794679

4680+
function 识别运营商(request) {
4681+
const cf = request?.cf;
4682+
const ASN运营商映射 = {
4683+
'4134': 'ct',
4684+
'4809': 'ct',
4685+
'4811': 'ct',
4686+
'4812': 'ct',
4687+
'4815': 'ct',
4688+
'4837': 'cu',
4689+
'4814': 'cu',
4690+
'9929': 'cu',
4691+
'17623': 'cu',
4692+
'17816': 'cu',
4693+
'9808': 'cmcc',
4694+
'24400': 'cmcc',
4695+
'56040': 'cmcc',
4696+
'56041': 'cmcc',
4697+
'56044': 'cmcc',
4698+
};
4699+
const 运营商关键词映射 = [
4700+
{ code: 'ct', pattern: /chinanet|chinatelecom|china telecom|cn2|shtel/ },
4701+
{ code: 'cmcc', pattern: /cmi|cmnet|chinamobile|china mobile|cmcc|mobile communications/ },
4702+
{ code: 'cu', pattern: /china169|china unicom|chinaunicom|cucc|cncgroup|cuii|netcom/ },
4703+
];
4704+
if (String(cf?.country || '').toLowerCase() !== 'cn') return 'cf';
4705+
const 组织名称 = String(cf?.asOrganization || '').toLowerCase();
4706+
const 命中运营商 = 运营商关键词映射.find(({ pattern }) => pattern.test(组织名称))?.code;
4707+
return 命中运营商 || ASN运营商映射[String(cf?.asn || '')] || 'cf';
4708+
}
4709+
46804710
async function 生成随机IP(request, count = 16, 指定端口 = -1, TLS = true) {
4681-
const ISP配置 = {
4682-
'9808': { file: 'cmcc', name: 'CF移动优选' },
4683-
'4837': { file: 'cu', name: 'CF联通优选' },
4684-
'17623': { file: 'cu', name: 'CF联通优选' },
4685-
'17816': { file: 'cu', name: 'CF联通优选' },
4686-
'4134': { file: 'ct', name: 'CF电信优选' },
4711+
const url = new URL(request.url);
4712+
const 查询参数运营商 = String(url.searchParams.get('asOrg') || '').toLowerCase();
4713+
const 运营商文件标识 = ['ct', 'cu', 'cmcc', 'cf'].includes(查询参数运营商) ? 查询参数运营商 : 识别运营商(request);
4714+
const 运营商名称映射 = {
4715+
cmcc: 'CF移动优选',
4716+
cu: 'CF联通优选',
4717+
ct: 'CF电信优选',
4718+
cf: 'CF官方优选',
46874719
};
4688-
const asn = request.cf.asn, isp = ISP配置[asn];
4689-
const cidr_url = isp ? `https://raw.githubusercontent.com/cmliu/cmliu/main/CF-CIDR/${isp.file}.txt` : 'https://raw.githubusercontent.com/cmliu/cmliu/main/CF-CIDR.txt';
4690-
const cfname = isp?.name || 'CF官方优选';
4720+
const cidr_url = 运营商文件标识 === 'cf' ? 'https://raw.githubusercontent.com/cmliu/cmliu/main/CF-CIDR.txt' : `https://raw.githubusercontent.com/cmliu/cmliu/main/CF-CIDR/${运营商文件标识}.txt`;
4721+
const cfname = 运营商名称映射[运营商文件标识] || 'CF官方优选';
46914722
const cfport = TLS ? [443, 2053, 2083, 2087, 2096, 8443] : [80, 8080, 8880, 2052, 2082, 2086, 2095];
46924723
let cidrList = [];
46934724
try { const res = await fetch(cidr_url); cidrList = res.ok ? await 整理成数组(await res.text()) : ['104.16.0.0/13'] } catch { cidrList = ['104.16.0.0/13'] }

0 commit comments

Comments
 (0)