Spaces:
Runtime error
Runtime error
Download network_fix.js from Brozy123/LineUp-Bot: direct link, hf CLI and curl.
- Browser
- Download file 1.96 kB
-
https://huggingface.co/spaces/Brozy123/LineUp-Bot/resolve/refs%2Fpr%2F1/network_fix.js
- Command line
-
hf download hf://spaces/Brozy123/LineUp-Bot@refs/pr/1/network_fix.js
-
curl -L -o network_fix.js https://huggingface.co/spaces/Brozy123/LineUp-Bot/resolve/refs%2Fpr%2F1/network_fix.js
1.96 kB
| const https = require('https'); | |
| const http = require('http'); | |
| const dns = require('dns'); | |
| const { Agent, setGlobalDispatcher } = require('undici'); | |
| /** | |
| * Professional Network Resilience Engine | |
| * Implements a stealth failover system for restricted environments. | |
| */ | |
| // Use official Discord domains only (explicitly excludes legacy discordapp.com). | |
| const FALLBACK_DOMAINS = ['discord.com', 'canary.discord.com', 'ptb.discord.com']; | |
| let active_index = 0; | |
| function applyAdvancedFixes() { | |
| const target = FALLBACK_DOMAINS[active_index]; | |
| console.log(`[NETWORK] Stealth Failover Active: Using ${target} bridge.`); | |
| // 1. Force IPv4 Priority (Standard for HF Stability) | |
| if (dns.setDefaultResultOrder) dns.setDefaultResultOrder('ipv4first'); | |
| // 2. Low-Level DNS Hijacking | |
| // This ensures that even if a library hardcodes 'discord.com', it gets the IP of our bridge. | |
| const originalLookup = dns.lookup; | |
| dns.lookup = function(hostname, options, callback) { | |
| if (typeof options === 'function') { callback = options; options = {}; } | |
| let h = hostname; | |
| if (hostname.includes('discord.com') && !hostname.includes('gateway') && !hostname.includes(target)) { | |
| h = target; | |
| } | |
| return originalLookup(h, options, callback); | |
| }; | |
| // 3. Optimized Connection Pooling | |
| const agent = new Agent({ | |
| connect: { | |
| timeout: 30000, | |
| family: 4, | |
| servername: target // Critical for TLS Handshake consistency | |
| }, | |
| pipelining: 1, | |
| keepAliveTimeout: 60000 | |
| }); | |
| setGlobalDispatcher(agent); | |
| // 4. Legacy Module Support | |
| https.globalAgent.options.family = 4; | |
| } | |
| function rotateEndpoint() { | |
| active_index = (active_index + 1) % FALLBACK_DOMAINS.length; | |
| applyAdvancedFixes(); | |
| } | |
| function getTargetDomain() { | |
| return FALLBACK_DOMAINS[active_index]; | |
| } | |
| module.exports = { applyAdvancedFixes, rotateEndpoint, getTargetDomain }; | |