mirror of
https://github.com/lush2020/edgetunnel.git
synced 2026-03-22 01:22:21 +08:00
fix: 优化优选订阅生成逻辑,添加其他节点链接并确保订阅内容正确编码
This commit is contained in:
18
_worker.js
18
_worker.js
@@ -221,13 +221,15 @@ export default {
|
||||
let 订阅内容 = '';
|
||||
if (订阅类型 === 'mixed') {
|
||||
const 节点路径 = (url.searchParams.has('clash') || ua.includes('clash') || ua.includes('meta') || ua.includes('mihomo')) && 协议类型 == 'tro' + 'jan' ? config_JSON.PATH + '?ed=2560' : config_JSON.PATH;
|
||||
const 完整优选列表 = config_JSON.优选订阅生成.本地IP库.随机IP ? (await 生成随机IP(request, config_JSON.优选订阅生成.本地IP库.随机数量))[0] : await env.KV.get('ADD.txt') ? await 整理成数组(await env.KV.get('ADD.txt')) : (await 生成随机IP(request, config_JSON.优选订阅生成.本地IP库.随机数量))[0];
|
||||
const 优选API = [], 优选IP = [], 其他节点 = [];
|
||||
for (const 元素 of 完整优选列表) {
|
||||
if (元素.toLowerCase().startsWith('https://') || 元素.toLowerCase().startsWith('http://')) 优选API.push(元素);
|
||||
else if (元素.toLowerCase().includes('://')) 其他节点.push(元素);
|
||||
else 优选IP.push(元素);
|
||||
}
|
||||
const 其他节点LINK = 其他节点.join('\n') + '\n';
|
||||
if (!url.searchParams.has('sub') && config_JSON.优选订阅生成.local) { // 本地生成订阅
|
||||
const 完整优选列表 = config_JSON.优选订阅生成.本地IP库.随机IP ? (await 生成随机IP(request, config_JSON.优选订阅生成.本地IP库.随机数量))[0] : await env.KV.get('ADD.txt') ? await 整理成数组(await env.KV.get('ADD.txt')) : (await 生成随机IP(request, config_JSON.优选订阅生成.本地IP库.随机数量))[0];
|
||||
const 优选API = [], 优选IP = [];
|
||||
for (const 元素 of 完整优选列表) {
|
||||
if (元素.toLowerCase().startsWith('https://') || 元素.toLowerCase().startsWith('http://')) 优选API.push(元素);
|
||||
else 优选IP.push(元素);
|
||||
}
|
||||
const 优选API的IP = await 请求优选API(优选API);
|
||||
const 完整优选IP = [...new Set(优选IP.concat(优选API的IP))];
|
||||
订阅内容 = 完整优选IP.map(原始地址 => {
|
||||
@@ -253,14 +255,14 @@ export default {
|
||||
|
||||
return `${协议类型}://${config_JSON.UUID}@${节点地址}:${节点端口}?security=tls&type=${config_JSON.传输协议}&host=${config_JSON.HOST}&sni=${config_JSON.HOST}&path=${encodeURIComponent(节点路径)}&fragment=${encodeURIComponent('1,40-60,30-50,tlshello')}&encryption=none${config_JSON.跳过证书验证 ? '&allowInsecure=1' : ''}#${encodeURIComponent(节点备注)}`;
|
||||
}).filter(item => item !== null).join('\n');
|
||||
订阅内容 = btoa(订阅内容);
|
||||
订阅内容 = btoa(其他节点LINK + 订阅内容);
|
||||
} else { // 优选订阅生成器
|
||||
let 优选订阅生成器HOST = url.searchParams.get('sub') || config_JSON.优选订阅生成.SUB;
|
||||
优选订阅生成器HOST = 优选订阅生成器HOST && !/^https?:\/\//i.test(优选订阅生成器HOST) ? `https://${优选订阅生成器HOST}` : 优选订阅生成器HOST;
|
||||
const 优选订阅生成器URL = `${优选订阅生成器HOST}/sub?host=example.com&${协议类型 === ('v' + 'le' + 'ss') ? 'uuid' : 'pw'}=00000000-0000-4000-0000-000000000000&path=${encodeURIComponent(节点路径)}&type=${config_JSON.传输协议}`;
|
||||
try {
|
||||
const response = await fetch(优选订阅生成器URL, { headers: { 'User-Agent': 'v2rayN/edge' + 'tunnel (https://github.com/cmliu/edge' + 'tunnel)' } });
|
||||
if (response.ok) 订阅内容 = await response.text();
|
||||
if (response.ok) 订阅内容 = btoa(其他节点LINK + atob(await response.text()));
|
||||
else return new Response('优选订阅生成器异常:' + response.statusText, { status: response.status });
|
||||
} catch (error) {
|
||||
return new Response('优选订阅生成器异常:' + error.message, { status: 403 });
|
||||
|
||||
Reference in New Issue
Block a user