mirror of
https://github.com/lush2020/edgetunnel.git
synced 2026-03-24 00:48:39 +08:00
Update worker.js
This commit is contained in:
53
worker.js
53
worker.js
@@ -816,7 +816,46 @@ async function getVLESSConfig(userID, hostName, sub, userAgent) {
|
|||||||
return `Error fetching content: ${error.message}`;
|
return `Error fetching content: ${error.message}`;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return 'Error: fetch is not available in this environment.';
|
return 'Error: fetch is not available in this environment.';//
|
||||||
|
}
|
||||||
|
} else if (sub && userAgent.includes('sing-box')) {
|
||||||
|
// 如果sub不为空且UA为sing-box,则发起特定请求
|
||||||
|
let singBoxVersion = null;
|
||||||
|
|
||||||
|
// 提取sing-box版本号
|
||||||
|
const match = userAgent.match(/sing-box (\d+\.\d+\.\d+)/);
|
||||||
|
if (match) {
|
||||||
|
singBoxVersion = match[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (singBoxVersion && compareVersions(singBoxVersion, '1.8.0') >= 0) {
|
||||||
|
// 如果 sing-box 版本是 1.8.0 或更高
|
||||||
|
if (typeof fetch === 'function') {
|
||||||
|
try {
|
||||||
|
const response = await fetch(`https://sing-box-subscribe.vercel.app/config/https:/${hostName}/${userID}`);
|
||||||
|
const content = await response.text();
|
||||||
|
return content;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('获取内容时出错:', error);
|
||||||
|
return `获取内容时出错: ${error.message}`;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return '错误: 在此环境中不支持 fetch。';
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 如果 sing-box 版本低于 1.8.0
|
||||||
|
if (typeof fetch === 'function') {
|
||||||
|
try {
|
||||||
|
const response = await fetch(`https://sub2singbox.fuck.cloudns.biz/config/https:/${hostName}/${userID}`);
|
||||||
|
const content = await response.text();
|
||||||
|
return content;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('获取内容时出错:', error);
|
||||||
|
return `获取内容时出错: ${error.message}`;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return '错误: 在此环境中不支持 fetch。';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// 如果sub不为空且UA,则发起一般请求
|
// 如果sub不为空且UA,则发起一般请求
|
||||||
@@ -833,5 +872,17 @@ async function getVLESSConfig(userID, hostName, sub, userAgent) {
|
|||||||
return 'Error: fetch is not available in this environment.';
|
return 'Error: fetch is not available in this environment.';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 辅助函数用于比较版本号
|
||||||
|
function compareVersions(version1, version2) {
|
||||||
|
const parts1 = version1.split('.').map(Number);
|
||||||
|
const parts2 = version2.split('.').map(Number);
|
||||||
|
|
||||||
|
for (let i = 0; i < 3; i++) {
|
||||||
|
if (parts1[i] < parts2[i]) return -1;
|
||||||
|
if (parts1[i] > parts2[i]) return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user