mirror of
https://github.com/lush2020/CF-Workers-SUB.git
synced 2026-03-21 11:02:41 +08:00
Update _worker.js
This commit is contained in:
27
_worker.js
27
_worker.js
@@ -190,7 +190,7 @@ export default {
|
|||||||
//throw new Error(`Error fetching subconverterUrl: ${subconverterResponse.status} ${subconverterResponse.statusText}`);
|
//throw new Error(`Error fetching subconverterUrl: ${subconverterResponse.status} ${subconverterResponse.statusText}`);
|
||||||
}
|
}
|
||||||
let subconverterContent = await subconverterResponse.text();
|
let subconverterContent = await subconverterResponse.text();
|
||||||
|
if (订阅格式 == 'clash') subconverterContent =await clashFix(subconverterContent);
|
||||||
return new Response(subconverterContent, {
|
return new Response(subconverterContent, {
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Disposition": `attachment; filename*=utf-8''${encodeURIComponent(FileName)}; filename=${FileName}`,
|
"Content-Disposition": `attachment; filename*=utf-8''${encodeURIComponent(FileName)}; filename=${FileName}`,
|
||||||
@@ -296,3 +296,28 @@ async function MD5MD5(text) {
|
|||||||
|
|
||||||
return secondHex.toLowerCase();
|
return secondHex.toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function clashFix(content) {
|
||||||
|
if(content.includes('wireguard') && !content.includes('remote-dns-resolve')){
|
||||||
|
let lines;
|
||||||
|
if (content.includes('\r\n')){
|
||||||
|
lines = content.split('\r\n');
|
||||||
|
} else {
|
||||||
|
lines = content.split('\n');
|
||||||
|
}
|
||||||
|
|
||||||
|
let result = "";
|
||||||
|
for (let line of lines) {
|
||||||
|
if (line.includes('type: wireguard')) {
|
||||||
|
const 备改内容 = `, mtu: 1280, udp: true`;
|
||||||
|
const 正确内容 = `, mtu: 1280, remote-dns-resolve: true, udp: true`;
|
||||||
|
result += line.replace(new RegExp(备改内容, 'g'), 正确内容) + '\n';
|
||||||
|
} else {
|
||||||
|
result += line + '\n';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
content = result;
|
||||||
|
}
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user