Brozy123 commited on
Commit
e31ada2
·
verified ·
1 Parent(s): d26bb0a

Update network_fix.js

Browse files
Files changed (1) hide show
  1. network_fix.js +21 -11
network_fix.js CHANGED
@@ -3,8 +3,8 @@ const http = require('http');
3
  const dns = require('dns');
4
 
5
  const DOMAINS = [
6
- "ptb.discord.com",
7
  "canary.discord.com",
 
8
  "discord.com"
9
  ];
10
  let current_index = 0;
@@ -40,14 +40,14 @@ function applyAdvancedFixes() {
40
  const _oldRequest = https.request;
41
  https.request = function(options, callback) {
42
  let opt = options;
43
- const isDiscord = (h) => h && (h.includes('discord.com') || h.includes('discordapp.com') || h.includes('dis.gd'));
44
- const isGateway = (h) => h && h.includes('discord.gg');
45
 
46
  if (typeof opt === 'string') {
47
- if (isDiscord(opt)) opt = opt.replace(/discord\.com|discordapp\.com|dis\.gd/, target_domain);
48
  } else {
49
  const host = opt.hostname || opt.host;
50
- if (isDiscord(host) && !isGateway(host)) {
51
  opt.hostname = target_domain;
52
  if (opt.host) opt.host = target_domain;
53
  opt.servername = target_domain;
@@ -69,10 +69,19 @@ function applyAdvancedFixes() {
69
  try {
70
  const undici = require('undici');
71
  const dispatcher = new undici.Agent({
72
- connect: {
73
- servername: target_domain,
74
- family: 4,
75
- timeout: 30000 // 30s connection timeout
 
 
 
 
 
 
 
 
 
76
  },
77
  pipelining: 1,
78
  keepAliveTimeout: 60000,
@@ -93,8 +102,9 @@ function applyAdvancedFixes() {
93
  try {
94
  const url = new URL(urlStr);
95
  const isDiscord = (h) => h && (h.includes('discord.com') || h.includes('discordapp.com') || h.includes('discordapp.net') || h.includes('dis.gd') || h.includes('discord.gg'));
96
- if (isDiscord(url.hostname)) {
97
- // Replace the hostname entirely with our target domain
 
98
  url.hostname = DOMAINS[current_index];
99
  }
100
  return _oldFetch.call(this, url.toString(), init);
 
3
  const dns = require('dns');
4
 
5
  const DOMAINS = [
 
6
  "canary.discord.com",
7
+ "ptb.discord.com",
8
  "discord.com"
9
  ];
10
  let current_index = 0;
 
40
  const _oldRequest = https.request;
41
  https.request = function(options, callback) {
42
  let opt = options;
43
+ const isDiscord = (h) => h && (h.includes('discord.com') || h.includes('discordapp.com') || h.includes('dis.gd') || h.includes('discord.gg') || h.includes('discordapp.net'));
44
+ const isAsset = (h) => h && (h.includes('cdn.discord') || h.includes('media.discord'));
45
 
46
  if (typeof opt === 'string') {
47
+ if (isDiscord(opt) && !isAsset(opt)) opt = opt.replace(/discord\.com|discordapp\.com|dis\.gd|discord\.gg/, target_domain);
48
  } else {
49
  const host = opt.hostname || opt.host;
50
+ if (isDiscord(host) && !isAsset(host)) {
51
  opt.hostname = target_domain;
52
  if (opt.host) opt.host = target_domain;
53
  opt.servername = target_domain;
 
69
  try {
70
  const undici = require('undici');
71
  const dispatcher = new undici.Agent({
72
+ connect: (opts, cb) => {
73
+ const isDiscord = (h) => h && (h.includes('discord.com') || h.includes('discordapp.com') || h.includes('dis.gd') || h.includes('discord.gg') || h.includes('discordapp.net'));
74
+ const isAsset = (h) => h && (h.includes('cdn.discord') || h.includes('media.discord'));
75
+
76
+ let targetOpts = { ...opts };
77
+ if (isDiscord(opts.hostname) && !isAsset(opts.hostname)) {
78
+ targetOpts.servername = target_domain;
79
+ }
80
+
81
+ return undici.buildConnector({
82
+ family: 4,
83
+ timeout: 30000
84
+ })(targetOpts, cb);
85
  },
86
  pipelining: 1,
87
  keepAliveTimeout: 60000,
 
102
  try {
103
  const url = new URL(urlStr);
104
  const isDiscord = (h) => h && (h.includes('discord.com') || h.includes('discordapp.com') || h.includes('discordapp.net') || h.includes('dis.gd') || h.includes('discord.gg'));
105
+ const isAsset = (h) => h && (h.includes('cdn.discord') || h.includes('media.discord'));
106
+
107
+ if (isDiscord(url.hostname) && !isAsset(url.hostname)) {
108
  url.hostname = DOMAINS[current_index];
109
  }
110
  return _oldFetch.call(this, url.toString(), init);