-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
74 lines (64 loc) · 1.95 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
66
67
68
69
70
71
72
73
74
const { default: axios } = require("axios");
const { sleep } = require("./utils");
/**
* http://www.yescaptcha.com/
* https://yescaptcha.atlassian.net/wiki/spaces/YESCAPTCHA/overview?homepageId=33020
*/
class Solver {
constructor(apikey, options = {}) {
this._apikey = apikey;
this._pollingFrequency = options.pollingFrequency || 5000;
this._verbose = options.verbose || false;
this._baseUrl = options.baseUrl || 'https://api.yescaptcha.com';
}
get apikey() { return this._apikey; }
get pollingFrequency() { return this._pollingFrequency; }
set apikey(update) { this._apikey = update; }
async pollResponse(taskId) {
let data = {
clientKey: this.apikey,
taskId
}
await sleep(this.pollingFrequency);
const response = await axios.post(`${this._baseUrl}/getTaskResult`, data)
// console.log(response)
if (response.data.errorId == 0) {
switch (response.data.status) {
case 'ready': return { data: response.data.solution.gRecaptchaResponse, taskId };
case "processing":
if (this._verbose) {
console.log('task processing')
}
return this.pollResponse(taskId);
default: {
throw new Error(response.data.errorDescription);
}
}
} else {
throw new Error(response.data.errorDescription)
}
}
async recaptcha(websiteKey, websiteURL, args = { type: 'NoCaptchaTaskProxyless' }) {
let data = {
clientKey: this.apikey,
task: {
websiteURL,
websiteKey,
softID: 2305,
...args
}
}
const response = await axios.post(`${this._baseUrl}/createTask`, data)
// console.log(response)
if (response.data.errorId == 0) {
if (this._verbose) {
console.log(`create task: ${response.data.taskId}`)
}
return this.pollResponse(response.data.taskId);
}
throw new Error(response.data.errorDescription);
}
}
module.exports = {
Solver
}