Mohammed Foud commited on
Commit
6570f44
·
1 Parent(s): e7a4a90

first commit

Browse files
Files changed (1) hide show
  1. src/AccountManager.js +24 -1
src/AccountManager.js CHANGED
@@ -11,12 +11,35 @@ async function getFreeProxy() {
11
  try {
12
  const response = await axios.get('https://www.proxy-list.download/api/v1/get?type=https');
13
  const proxyList = response.data.split('\n').filter(Boolean);
14
- return proxyList[Math.floor(Math.random() * proxyList.length)]; // Select a random proxy
 
 
 
 
 
 
 
15
  } catch (error) {
16
  console.error('Error fetching proxy:', error);
17
  return null;
18
  }
19
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  class WhatsAppAccountManager {
21
  constructor(accountId) {
22
  this.accountId = accountId;
 
11
  try {
12
  const response = await axios.get('https://www.proxy-list.download/api/v1/get?type=https');
13
  const proxyList = response.data.split('\n').filter(Boolean);
14
+
15
+ for (let proxy of proxyList) {
16
+ console.log("test => ", proxy);
17
+ let isValid = await testProxy(proxy);
18
+ if (isValid) return proxy;
19
+ }
20
+
21
+ return null;
22
  } catch (error) {
23
  console.error('Error fetching proxy:', error);
24
  return null;
25
  }
26
  }
27
+
28
+ async function testProxy(proxy) {
29
+ try {
30
+ await axios.get('https://web.whatsapp.com/', {
31
+ proxy: {
32
+ host: proxy.split(':')[0],
33
+ port: proxy.split(':')[1]
34
+ },
35
+ timeout: 5000
36
+ });
37
+ return true;
38
+ } catch {
39
+ return false;
40
+ }
41
+ }
42
+
43
  class WhatsAppAccountManager {
44
  constructor(accountId) {
45
  this.accountId = accountId;