proxy-rotator-js 1.0.4 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/Proxy.js +2 -2
- package/src/ProxyRotator.js +15 -14
package/package.json
CHANGED
package/src/Proxy.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
class Proxy {
|
|
2
|
-
constructor(proxy, protocol = null) {
|
|
2
|
+
constructor(proxy, protocol = null, assumeAlive = false) {
|
|
3
3
|
// if proxy string starts with protocol
|
|
4
4
|
if( proxy.includes('://') ){
|
|
5
5
|
this.protocol = proxy.split('://')[0];
|
|
@@ -13,7 +13,7 @@ class Proxy {
|
|
|
13
13
|
// the proxy
|
|
14
14
|
this.proxy = `${(this.protocol)? this.protocol+'://' : ''}${this.ip}:${this.port}`;
|
|
15
15
|
// status can be 'new', 'alive', 'dead'
|
|
16
|
-
this.status = 'new';
|
|
16
|
+
this.status = (assumeAlive)? 'alive' : 'new';
|
|
17
17
|
this.changeTimeStamp = Date.now();
|
|
18
18
|
}
|
|
19
19
|
// method to return as string
|
package/src/ProxyRotator.js
CHANGED
|
@@ -6,24 +6,13 @@ class ProxyRotator {
|
|
|
6
6
|
constructor(proxies, options={} ){
|
|
7
7
|
this.pool = new Queue();
|
|
8
8
|
this.graveyard = [];
|
|
9
|
-
// examine proxies passed
|
|
10
|
-
// check if it is a file path
|
|
11
|
-
if( typeof proxies === 'string' ){
|
|
12
|
-
// parse file
|
|
13
|
-
proxies = this._parseFile(proxies);
|
|
14
|
-
// add proxies to queue
|
|
15
|
-
proxies.forEach( p => this._add(p) );
|
|
16
|
-
}else if( this._isArray(proxies) ){
|
|
17
|
-
// add proxies to queue
|
|
18
|
-
proxies.forEach( p => this._add(p) );
|
|
19
|
-
}
|
|
20
9
|
// handle options
|
|
21
10
|
let { proxyType, revive_timer, shuffle, protocol, assume_aliveness, check_on_next } = options;
|
|
22
11
|
// how long to wait before reviving a dead proxy
|
|
23
12
|
// default: 30 minutes
|
|
24
13
|
this.revive_timer = revive_timer ?? 1000 * 60 * 30;
|
|
25
14
|
// return type of proxy, either 'string' or 'object'
|
|
26
|
-
this.proxyType = _handleProxyTypeInput(proxyType);
|
|
15
|
+
this.proxyType = proxyType? this._handleProxyTypeInput(proxyType) : 'string';
|
|
27
16
|
// assume a a protocol for all proxies
|
|
28
17
|
this.protocol = protocol ?? null;
|
|
29
18
|
// shuffle the proxies before adding them to the queue
|
|
@@ -32,6 +21,17 @@ class ProxyRotator {
|
|
|
32
21
|
this.assume_aliveness = assume_aliveness ?? false;
|
|
33
22
|
// check if proxies are alive when they are added to the queue
|
|
34
23
|
this.check_on_next = check_on_next ?? false;
|
|
24
|
+
// examine proxies passed
|
|
25
|
+
// check if it is a file path
|
|
26
|
+
if( typeof proxies === 'string' ){
|
|
27
|
+
// parse file
|
|
28
|
+
proxies = this._parseFile(proxies);
|
|
29
|
+
// add proxies to queue
|
|
30
|
+
proxies.forEach( p => this._add(p) );
|
|
31
|
+
}else if( this._isArray(proxies) ){
|
|
32
|
+
// add proxies to queue
|
|
33
|
+
proxies.forEach( p => this._add(p) );
|
|
34
|
+
}
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
getGraveyard(){ return this.graveyard.map(p => p.proxy) }
|
|
@@ -50,7 +50,7 @@ class ProxyRotator {
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
_add(proxy){ // add proxy to queue
|
|
53
|
-
let p = new Proxy(proxy);
|
|
53
|
+
let p = new Proxy(proxy, this.protocol, this.assume_aliveness);
|
|
54
54
|
this.pool.enqueue(p);
|
|
55
55
|
}
|
|
56
56
|
|
|
@@ -141,7 +141,8 @@ class ProxyRotator {
|
|
|
141
141
|
return array;
|
|
142
142
|
}
|
|
143
143
|
|
|
144
|
-
_handleProxyTypeInput(proxyType){
|
|
144
|
+
_handleProxyTypeInput(proxyType=null){
|
|
145
|
+
if(proxyType === null) return null;
|
|
145
146
|
proxyType = proxyType.toLowerCase();
|
|
146
147
|
if(proxyType === 'str') proxyType = 'string';
|
|
147
148
|
if(proxyType === 'obj') proxyType = 'object';
|