Spaces:
Runtime error
Runtime error
fix: restore high-power network fix and increase timeouts to 5m
Browse files- index.js +1 -1
- network_fix.js +47 -8
index.js
CHANGED
|
@@ -52,7 +52,7 @@ const client = new Client({
|
|
| 52 |
],
|
| 53 |
partials: [Partials.Message, Partials.Channel, Partials.Reaction],
|
| 54 |
rest: {
|
| 55 |
-
timeout:
|
| 56 |
agent: networkFix.getDispatcher(),
|
| 57 |
},
|
| 58 |
// Impersonate a desktop client to bypass firewall connection killing
|
|
|
|
| 52 |
],
|
| 53 |
partials: [Partials.Message, Partials.Channel, Partials.Reaction],
|
| 54 |
rest: {
|
| 55 |
+
timeout: 300_000, // 5 minutes
|
| 56 |
agent: networkFix.getDispatcher(),
|
| 57 |
},
|
| 58 |
// Impersonate a desktop client to bypass firewall connection killing
|
network_fix.js
CHANGED
|
@@ -1,19 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
/**
|
| 2 |
-
*
|
| 3 |
*
|
| 4 |
-
*
|
| 5 |
-
*
|
|
|
|
| 6 |
*/
|
| 7 |
|
| 8 |
function applyAdvancedFixes() {
|
| 9 |
-
console.log(`[NETWORK]
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
|
| 14 |
-
return null; // Let the library use its default agent
|
| 15 |
}
|
| 16 |
|
|
|
|
| 17 |
function rotateEndpoint() {}
|
| 18 |
function getTargetDomain() { return 'discord.com'; }
|
| 19 |
|
|
|
|
| 1 |
+
const dns = require('dns');
|
| 2 |
+
const fs = require('fs');
|
| 3 |
+
const tls = require('tls');
|
| 4 |
+
|
| 5 |
/**
|
| 6 |
+
* HIGH-POWER GHOST MODE for Hugging Face.
|
| 7 |
*
|
| 8 |
+
* 1. Overrides TLS to prevent socket drops.
|
| 9 |
+
* 2. Forces IPv4 strictly.
|
| 10 |
+
* 3. Monkey-patches dns.lookup to mask connection.
|
| 11 |
*/
|
| 12 |
|
| 13 |
function applyAdvancedFixes() {
|
| 14 |
+
console.log(`[NETWORK] Activating High-Power Ghost Mode...`);
|
| 15 |
+
|
| 16 |
+
// 1. Force TLS to be permissive
|
| 17 |
+
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
|
| 18 |
+
tls.DEFAULT_MIN_VERSION = 'TLSv1.2';
|
| 19 |
+
|
| 20 |
+
// 2. Strict IPv4
|
| 21 |
+
if (dns.setDefaultResultOrder) {
|
| 22 |
+
dns.setDefaultResultOrder('ipv4first');
|
| 23 |
+
}
|
| 24 |
+
const originalLookup = dns.lookup;
|
| 25 |
+
dns.lookup = function(hostname, options, callback) {
|
| 26 |
+
if (typeof options === 'function') { callback = options; options = { family: 4 }; }
|
| 27 |
+
else if (typeof options === 'number') { options = { family: 4 }; }
|
| 28 |
+
else if (!options) { options = { family: 4 }; }
|
| 29 |
+
else { options.family = 4; }
|
| 30 |
+
return originalLookup(hostname, options, callback);
|
| 31 |
+
};
|
| 32 |
+
|
| 33 |
+
// 3. Configure Network Dispatcher with 120s timeouts
|
| 34 |
+
try {
|
| 35 |
+
const { setGlobalDispatcher, Agent } = require('undici');
|
| 36 |
+
const agent = new Agent({
|
| 37 |
+
connect: {
|
| 38 |
+
timeout: 120_000,
|
| 39 |
+
family: 4,
|
| 40 |
+
rejectUnauthorized: false
|
| 41 |
+
},
|
| 42 |
+
headersTimeout: 120_000,
|
| 43 |
+
bodyTimeout: 120_000
|
| 44 |
+
});
|
| 45 |
+
setGlobalDispatcher(agent);
|
| 46 |
+
this._dispatcher = agent;
|
| 47 |
+
|
| 48 |
+
// Desktop User Agent
|
| 49 |
+
process.env.UNDICI_UA = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36';
|
| 50 |
+
} catch (e) {}
|
| 51 |
|
| 52 |
+
console.log('[NETWORK] High-Power Ghost Mode Active.');
|
|
|
|
| 53 |
}
|
| 54 |
|
| 55 |
+
function getDispatcher() { return this._dispatcher; }
|
| 56 |
function rotateEndpoint() {}
|
| 57 |
function getTargetDomain() { return 'discord.com'; }
|
| 58 |
|