puppyproxy 1.1.1 → 1.1.3
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/README.md +2 -0
- package/package.json +1 -1
- package/src/PuppyProxy.js +4 -0
- package/src/network/RequestClient.js +29 -0
- package/src/utils.js +9 -4
package/README.md
CHANGED
|
@@ -50,6 +50,8 @@ log.highlight("TESTING: runCollector");
|
|
|
50
50
|
|
|
51
51
|
await pp.init(true); // true forces run the collector
|
|
52
52
|
|
|
53
|
+
console.log(pp.request.createProxyRequestPool().length, "proxies in the pool after init");
|
|
54
|
+
|
|
53
55
|
log.highlight("TESTING: RequestClient");
|
|
54
56
|
|
|
55
57
|
log.bold("----- pp.request.fetch")
|
package/package.json
CHANGED
package/src/PuppyProxy.js
CHANGED
|
@@ -97,6 +97,10 @@ export default class PuppyProxy {
|
|
|
97
97
|
return this.request.createProxyRequest(url, options);
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
+
createProxyRequestPool(url, options = {}) {
|
|
101
|
+
return this.request.createProxyRequestPool(url, options);
|
|
102
|
+
}
|
|
103
|
+
|
|
100
104
|
/**
|
|
101
105
|
* Trigger the proxy collection worker
|
|
102
106
|
*/
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import log from 'puppylog';
|
|
2
2
|
import id from 'puppyid';
|
|
3
3
|
import { originals } from '../constants.js';
|
|
4
|
+
import scrambled from 'puppyscrambled';
|
|
5
|
+
import { createBasicAgent } from '../utils.js';
|
|
4
6
|
|
|
5
7
|
export class ProxyRequest {
|
|
6
8
|
constructor(requestClient, url, options = {}) {
|
|
@@ -281,4 +283,31 @@ export default class RequestClient {
|
|
|
281
283
|
createProxyRequest(url, options) {
|
|
282
284
|
return new ProxyRequest(this, url, options);
|
|
283
285
|
}
|
|
286
|
+
|
|
287
|
+
//return an array of ProxyRequest objects, one for each proxy
|
|
288
|
+
createProxyRequestPool(url, options = {}) {
|
|
289
|
+
const oldLOG = this.config.LOG;
|
|
290
|
+
this.config.LOG = {}; //suppress logs for this operation
|
|
291
|
+
let currentWithoutNew = 0;
|
|
292
|
+
const withoutNewLimit = 1000;
|
|
293
|
+
const proxyRequests = [];
|
|
294
|
+
const uniqueProxies = [];
|
|
295
|
+
|
|
296
|
+
while (currentWithoutNew < withoutNewLimit) {
|
|
297
|
+
const pr = this.createProxyRequest(url, { ...options });
|
|
298
|
+
const proxy = pr.options.AGENT?.USINGSCRAPED;
|
|
299
|
+
|
|
300
|
+
if (proxy && !uniqueProxies.includes(proxy)) {
|
|
301
|
+
pr.id = scrambled.getScrambled();
|
|
302
|
+
console.log(pr.id, pr.options.AGENT.___id, "added proxy to pool:", proxy);
|
|
303
|
+
pr.options.AGENT.___id = pr.id;
|
|
304
|
+
proxyRequests.push(pr);
|
|
305
|
+
uniqueProxies.push(proxy);
|
|
306
|
+
currentWithoutNew = 0;
|
|
307
|
+
} else currentWithoutNew++;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
this.config.LOG = oldLOG;
|
|
311
|
+
return proxyRequests;
|
|
312
|
+
}
|
|
284
313
|
}
|
package/src/utils.js
CHANGED
|
@@ -4,9 +4,14 @@ import { HttpsProxyAgent } from 'https-proxy-agent';
|
|
|
4
4
|
|
|
5
5
|
export function createBasicAgent(proxyUrl) {
|
|
6
6
|
if (!proxyUrl) return null;
|
|
7
|
+
|
|
8
|
+
let proxy = null;
|
|
7
9
|
|
|
8
|
-
if (proxyUrl.startsWith("socks"))
|
|
9
|
-
if (proxyUrl.startsWith("https"))
|
|
10
|
-
if (proxyUrl.startsWith("http"))
|
|
11
|
-
|
|
10
|
+
if (proxyUrl.startsWith("socks")) proxy = new SocksProxyAgent(proxyUrl);
|
|
11
|
+
else if (proxyUrl.startsWith("https")) proxy = new HttpsProxyAgent(proxyUrl);
|
|
12
|
+
else if (proxyUrl.startsWith("http")) proxy = new HttpProxyAgent(proxyUrl);
|
|
13
|
+
|
|
14
|
+
proxy.USINGSCRAPED = proxyUrl;
|
|
15
|
+
|
|
16
|
+
return proxy;
|
|
12
17
|
}
|