Brozy123 commited on
Commit
8b2df07
·
verified ·
1 Parent(s): 776deb8

Create ultimate_fix.js

Browse files
Files changed (1) hide show
  1. ultimate_fix.js +64 -0
ultimate_fix.js ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const dns = require('dns');
2
+ const tls = require('tls');
3
+ const fs = require('fs');
4
+
5
+ /**
6
+ * THE ULTIMATE FIX FOR HUGGING FACE SPACES
7
+ * This file forces the bot to bypass all network restrictions manually.
8
+ */
9
+
10
+ console.log("[ULTIMATE FIX] Booting network bypass logic...");
11
+
12
+ // 1. Force the system to use IPv4 only
13
+ if (dns.setDefaultResultOrder) {
14
+ dns.setDefaultResultOrder('ipv4first');
15
+ }
16
+
17
+ // 2. Monkey-patch the global DNS system (Failsafe)
18
+ const originalLookup = dns.lookup;
19
+ dns.lookup = function(hostname, options, callback) {
20
+ if (typeof options === 'function') {
21
+ callback = options;
22
+ options = { family: 4 };
23
+ } else if (typeof options === 'number') {
24
+ options = { family: 4 };
25
+ } else if (!options) {
26
+ options = { family: 4 };
27
+ } else {
28
+ options.family = 4;
29
+ }
30
+ return originalLookup(hostname, options, callback);
31
+ };
32
+
33
+ // 3. Force TLS version compatibility
34
+ tls.DEFAULT_MIN_VERSION = 'TLSv1.2';
35
+ tls.DEFAULT_MIN_VERSION = 'TLSv1.2';
36
+ tls.DEFAULT_MAX_VERSION = 'TLSv1.3';
37
+
38
+ // 4. Force a fake Browser Identity globally
39
+ process.env.UNDICI_UA = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36';
40
+
41
+ // 5. Build and set a Global Network Agent with massive timeouts
42
+ try {
43
+ const { setGlobalDispatcher, Agent } = require('undici');
44
+ const dispatcher = new Agent({
45
+ connect: {
46
+ timeout: 120000, // 2 minutes
47
+ family: 4,
48
+ rejectUnauthorized: false
49
+ },
50
+ headersTimeout: 120000,
51
+ bodyTimeout: 120000
52
+ });
53
+ setGlobalDispatcher(dispatcher);
54
+ global.fixedDispatcher = dispatcher;
55
+ console.log("[ULTIMATE FIX] Global Network Dispatcher active.");
56
+ } catch (e) {
57
+ console.warn("[ULTIMATE FIX] Undici setup failed, using default (this is okay).");
58
+ }
59
+
60
+ console.log("[ULTIMATE FIX] Network system ready. All IPv6 and TLS blocks bypassed.");
61
+
62
+ module.exports = {
63
+ dispatcher: global.fixedDispatcher || null
64
+ };