forked from mitom/gimmeproxy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
65 lines (59 loc) · 1.61 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
const request = require('request-promise-native')
const randomstring = require('randomstring')
const url = require('url')
const QSOPTIONS = {
get: 'get',
post: 'post',
cookies: 'cookies',
referer: 'referer',
userAgent: 'user-agent',
https: 'supportsHttps',
anonymityLevel: 'anonymityLevel',
protocol: 'protocol',
port: 'port',
country: 'country',
maxCheckPeriod: 'maxCheckPeriod',
websites: 'websites',
minSpeed: 'minSpeed',
notCountry: 'notCountry',
ipPort: 'ipPort',
curl: 'curl',
}
const GimmeProxy = {
_userId: null,
_timeout: null,
_api_key: null,
_host: 'http://gimmeproxy.com',
_path: '/api/getProxy',
_timeout_path: '/api/get/',
config(config) {
if (config.userId) this._userId = config.userId || randomstring.generate(32)
if (config.timeout) this._timeout = config.timeout
if (config.api_key) this._api_key = config.api_key
},
getProxy({ timeout, get = true, api_key = null, ...rest } = {}) {
const _timeout = timeout || this._timeout || null
const _api_key = api_key || this._api_key || null
const options = {}
if (_timeout) {
this.config({});
options.timeout = _timeout
}
if (_api_key) {
options.api_key = api_key
}
if (get) {
options.get = true
}
return request(url.resolve(this._host,
timeout ? url.resolve(this._timeout_path, this._userId) : this._path
), {
qs: {
...options,
...Object.fromEntries(Object.entries(QSOPTIONS).filter(([key]) => rest[key]).map(([key, option]) => [option, rest[key]])),
},
json: true,
})
},
}
module.exports = GimmeProxy