mirror of
https://github.com/lush2020/edgetunnel.git
synced 2026-03-21 17:12:33 +08:00
Update _worker.js
This commit is contained in:
37
_worker.js
37
_worker.js
@@ -37,7 +37,8 @@ export default {
|
||||
*/
|
||||
async fetch(request, env, ctx) {
|
||||
try {
|
||||
const userAgent = request.headers.get('User-Agent').toLowerCase();
|
||||
const UA = request.headers.get('User-Agent') || 'null';
|
||||
const userAgent = UA.toLowerCase();
|
||||
userID = (env.UUID || userID).toLowerCase();
|
||||
proxyIP = env.PROXYIP || proxyIP;
|
||||
const proxyIPs = await ADD(proxyIP);
|
||||
@@ -69,7 +70,7 @@ export default {
|
||||
case '/':
|
||||
return new Response(JSON.stringify(request.cf, null, 4), { status: 200 });
|
||||
case `/${userID}`: {
|
||||
const vlessConfig = await getVLESSConfig(userID, request.headers.get('Host'), sub, userAgent, RproxyIP);
|
||||
const vlessConfig = await getVLESSConfig(userID, request.headers.get('Host'), sub, UA, RproxyIP, url);
|
||||
const now = Date.now();
|
||||
const timestamp = Math.floor(now / 1000);
|
||||
const expire = 4102329600;//2099-12-31
|
||||
@@ -81,6 +82,8 @@ export default {
|
||||
status: 200,
|
||||
headers: {
|
||||
"Content-Type": "text/plain;charset=utf-8",
|
||||
"Profile-Update-Interval": "6",
|
||||
"Subscription-Userinfo": `upload=${UD}; download=${UD}; total=${24 * 1099511627776}; expire=${expire}`,
|
||||
}
|
||||
});
|
||||
} else {
|
||||
@@ -896,19 +899,22 @@ function 配置信息(UUID, 域名地址) {
|
||||
return [v2ray,clash];
|
||||
}
|
||||
|
||||
let subParams = ['sub','base64','b64','clash','singbox','sb'];
|
||||
|
||||
/**
|
||||
* @param {string} userID
|
||||
* @param {string | null} hostName
|
||||
* @param {string} sub
|
||||
* @param {string} userAgent
|
||||
* @param {string} UA
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
async function getVLESSConfig(userID, hostName, sub, userAgent, RproxyIP) {
|
||||
async function getVLESSConfig(userID, hostName, sub, UA, RproxyIP, _url) {
|
||||
const userAgent = UA.toLowerCase();
|
||||
const Config = 配置信息(userID , hostName);
|
||||
const v2ray = Config[0];
|
||||
const clash = Config[1];
|
||||
// 如果sub为空,则显示原始内容
|
||||
if (!sub || sub === '') {
|
||||
if ((!sub || sub === '') && !subParams.some(_searchParams => _url.searchParams.has(_searchParams))) {
|
||||
|
||||
return `
|
||||
################################################################
|
||||
@@ -923,13 +929,26 @@ async function getVLESSConfig(userID, hostName, sub, userAgent, RproxyIP) {
|
||||
---------------------------------------------------------------
|
||||
################################################################
|
||||
`;
|
||||
} else if (sub && userAgent.includes('mozilla') && !userAgent.includes('linux x86')) {
|
||||
} else if (sub && userAgent.includes('mozilla') && !subParams.some(_searchParams => _url.searchParams.has(_searchParams))) {
|
||||
|
||||
return `
|
||||
################################################################
|
||||
Subscribe / sub 订阅地址, 支持 Base64、clash-meta、sing-box 订阅格式, 您的订阅内容由 ${sub} 提供维护支持, 自动获取ProxyIP: ${RproxyIP}.
|
||||
---------------------------------------------------------------
|
||||
快速自适应订阅地址:
|
||||
https://${hostName}/${userID}
|
||||
|
||||
Base64订阅地址:
|
||||
https://${hostName}/${userID}?sub
|
||||
https://${hostName}/${userID}?b64
|
||||
https://${hostName}/${userID}?base64
|
||||
|
||||
clash订阅地址:
|
||||
https://${hostName}/${userID}?clash
|
||||
|
||||
singbox订阅地址:
|
||||
https://${hostName}/${userID}?sb
|
||||
https://${hostName}/${userID}?singbox
|
||||
---------------------------------------------------------------
|
||||
################################################################
|
||||
v2ray
|
||||
@@ -967,9 +986,9 @@ async function getVLESSConfig(userID, hostName, sub, userAgent, RproxyIP) {
|
||||
|
||||
let url = `https://${sub}/sub?host=${fakeHostName}&uuid=${fakeUserID}&edgetunnel=cmliu&proxyip=${RproxyIP}`;
|
||||
let isBase64 = false;
|
||||
if (userAgent.includes('clash') && !userAgent.includes('nekobox')) {
|
||||
if ((userAgent.includes('clash') && !userAgent.includes('nekobox')) || ( _url.searchParams.has('clash') && !userAgent.includes('subconverter'))) {
|
||||
url = `https://${subconverter}/sub?target=clash&url=${encodeURIComponent(url)}&insert=false&config=${encodeURIComponent(subconfig)}&emoji=true&list=false&tfo=false&scv=true&fdn=false&sort=false&new_name=true`;
|
||||
} else if (userAgent.includes('sing-box') || userAgent.includes('singbox')) {
|
||||
} else if (userAgent.includes('sing-box') || userAgent.includes('singbox') || (( _url.searchParams.has('singbox') || _url.searchParams.has('sb')) && !userAgent.includes('subconverter'))) {
|
||||
url = `https://${subconverter}/sub?target=singbox&url=${encodeURIComponent(url)}&insert=false&config=${encodeURIComponent(subconfig)}&emoji=true&list=false&tfo=false&scv=true&fdn=false&sort=false&new_name=true`;
|
||||
} else {
|
||||
isBase64 = true;
|
||||
@@ -978,7 +997,7 @@ async function getVLESSConfig(userID, hostName, sub, userAgent, RproxyIP) {
|
||||
try {
|
||||
const response = await fetch(url ,{
|
||||
headers: {
|
||||
'User-Agent': 'CF-Workers-edgetunnel/cmliu'
|
||||
'User-Agent': `${UA} CF-Workers-edgetunnel/cmliu`
|
||||
}});
|
||||
const content = await response.text();
|
||||
return revertFakeInfo(content, userID, hostName, isBase64);
|
||||
|
||||
Reference in New Issue
Block a user