Spaces:
Runtime error
Runtime error
Update network_fix.js
Browse files- network_fix.js +14 -8
network_fix.js
CHANGED
|
@@ -52,16 +52,22 @@ function applyAdvancedFixes() {
|
|
| 52 |
http.globalAgent = new http.Agent(options);
|
| 53 |
|
| 54 |
try {
|
| 55 |
-
const
|
| 56 |
-
const dispatcher = new Agent({
|
| 57 |
connect: {
|
| 58 |
-
servername: target_domain
|
|
|
|
|
|
|
| 59 |
},
|
| 60 |
pipelining: 1,
|
| 61 |
-
keepAliveTimeout:
|
|
|
|
|
|
|
| 62 |
});
|
| 63 |
-
setGlobalDispatcher(dispatcher);
|
| 64 |
-
} catch (e) {
|
|
|
|
|
|
|
| 65 |
|
| 66 |
// Patch global fetch if it exists (Node 18+)
|
| 67 |
const globalObj = typeof globalThis !== 'undefined' ? globalThis : global;
|
|
@@ -69,9 +75,9 @@ function applyAdvancedFixes() {
|
|
| 69 |
const _oldFetch = globalObj.fetch;
|
| 70 |
globalObj.fetch = async function(input, init) {
|
| 71 |
let url = typeof input === 'string' ? input : (input.url || input.toString());
|
| 72 |
-
const isDiscord = (u) => u && (u.includes('discord.com') || u.includes('discordapp.com') || u.includes('dis.gd'));
|
| 73 |
if (isDiscord(url)) {
|
| 74 |
-
const newUrl = url.replace(/discord\.com|discordapp\.com|dis\.gd/, DOMAINS[current_index]);
|
| 75 |
return _oldFetch.call(this, newUrl, init);
|
| 76 |
}
|
| 77 |
return _oldFetch.call(this, input, init);
|
|
|
|
| 52 |
http.globalAgent = new http.Agent(options);
|
| 53 |
|
| 54 |
try {
|
| 55 |
+
const undici = require('undici');
|
| 56 |
+
const dispatcher = new undici.Agent({
|
| 57 |
connect: {
|
| 58 |
+
servername: target_domain,
|
| 59 |
+
family: 4,
|
| 60 |
+
timeout: 30000 // 30s connection timeout
|
| 61 |
},
|
| 62 |
pipelining: 1,
|
| 63 |
+
keepAliveTimeout: 60000,
|
| 64 |
+
bodyTimeout: 30000,
|
| 65 |
+
headersTimeout: 30000
|
| 66 |
});
|
| 67 |
+
undici.setGlobalDispatcher(dispatcher);
|
| 68 |
+
} catch (e) {
|
| 69 |
+
console.log("[!] NetworkFix: undici dispatcher not set:", e.message);
|
| 70 |
+
}
|
| 71 |
|
| 72 |
// Patch global fetch if it exists (Node 18+)
|
| 73 |
const globalObj = typeof globalThis !== 'undefined' ? globalThis : global;
|
|
|
|
| 75 |
const _oldFetch = globalObj.fetch;
|
| 76 |
globalObj.fetch = async function(input, init) {
|
| 77 |
let url = typeof input === 'string' ? input : (input.url || input.toString());
|
| 78 |
+
const isDiscord = (u) => u && (u.includes('discord.com') || u.includes('discordapp.com') || u.includes('dis.gd') || u.includes('discord.gg'));
|
| 79 |
if (isDiscord(url)) {
|
| 80 |
+
const newUrl = url.replace(/discord\.com|discordapp\.com|dis\.gd|discord\.gg/, DOMAINS[current_index]);
|
| 81 |
return _oldFetch.call(this, newUrl, init);
|
| 82 |
}
|
| 83 |
return _oldFetch.call(this, input, init);
|