recognize 2.0.0 → 3.0.0

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/index.js DELETED
@@ -1,150 +0,0 @@
1
- import { setTimeout } from "node:timers/promises";
2
- import got from "got";
3
-
4
- export const SOURCE = {
5
- RUCAPTCHA: "RUCAPTCHA",
6
- ANTIGATE: "ANTIGATE",
7
- CAPTCHA24: "CAPTCHA24",
8
- };
9
-
10
- const _SOURCE = {
11
- [SOURCE.RUCAPTCHA]: {
12
- baseUrl: "http://rucaptcha.com",
13
- soft_id: 768,
14
- },
15
- [SOURCE.ANTIGATE]: {
16
- baseUrl: "http://anti-captcha.com",
17
- soft_id: 720,
18
- },
19
- [SOURCE.CAPTCHA24]: {
20
- baseUrl: "http://captcha24.com",
21
- soft_id: 921,
22
- },
23
- };
24
-
25
- export default class Recognize {
26
- constructor(sourceCode, options) {
27
- if (!options || !options.key) throw new Error("not key");
28
- const source = _SOURCE[sourceCode];
29
- if (!source) throw new Error("invalid type");
30
- this.rp = got.extend({
31
- prefixUrl: source.baseUrl,
32
- resolveBodyOnly: true,
33
- responseType: "json",
34
- });
35
- this._options = {
36
- ...options,
37
- soft_id: source.soft_id,
38
- };
39
- }
40
-
41
- async _waitResult(id) {
42
- await setTimeout(1000);
43
- const { status, request } = await this.rp.get("res.php", {
44
- searchParams: { key: this._options.key, action: "get", id, json: 1 },
45
- });
46
-
47
- if (request === "CAPCHA_NOT_READY") return this._waitResult(id);
48
- else if (status === 0) return Promise.reject(request);
49
-
50
- return request;
51
- }
52
-
53
- async balanse() {
54
- const { request } = await this.rp.get("res.php", {
55
- searchParams: { key: this._options.key, action: "getbalance", json: 1 },
56
- });
57
-
58
- return request;
59
- }
60
-
61
- async solvingImage(buff, options = {}) {
62
- const { status, request } = await this.rp.post("in.php", {
63
- json: {
64
- ...options,
65
- soft_id: this._options.soft_id,
66
- method: "base64",
67
- key: this._options.key,
68
- body: buff.toString("base64"),
69
- json: 1,
70
- },
71
- });
72
-
73
- if (status === 1) {
74
- return { result: await this._waitResult(request), id: request };
75
- }
76
-
77
- return Promise.reject(request);
78
- }
79
-
80
- async solvingRecaptcha2(url, googleKey, options = {}) {
81
- const { status, request } = await this.rp.post("in.php", {
82
- json: {
83
- ...options,
84
- soft_id: this._options.soft_id,
85
- method: "userrecaptcha",
86
- key: this._options.key,
87
- pageurl: url,
88
- googlekey: googleKey,
89
- json: 1,
90
- },
91
- });
92
-
93
- if (status === 1) {
94
- return { result: await this._waitResult(request), id: request };
95
- }
96
-
97
- return Promise.reject(request);
98
- }
99
-
100
- async solvingRecaptcha3(url, googleKey, action, score = "0.3", options = {}) {
101
- const { status, request } = await this.rp.post("in.php", {
102
- json: {
103
- ...options,
104
- soft_id: this._options.soft_id,
105
- method: "userrecaptcha",
106
- version: "v3",
107
- action,
108
- min_score: score,
109
- key: this._options.key,
110
- pageurl: url,
111
- googlekey: googleKey,
112
- json: 1,
113
- },
114
- });
115
-
116
- if (status === 1) {
117
- return { result: await this._waitResult(request), id: request };
118
- }
119
-
120
- return Promise.reject(request);
121
- }
122
-
123
- async reportBad(id) {
124
- const { status, request } = await this.rp.get("res.php", {
125
- searchParams: {
126
- key: this._options.key,
127
- action: "reportbad",
128
- id,
129
- json: 1,
130
- },
131
- });
132
-
133
- if (status === 0) return false;
134
- return true;
135
- }
136
-
137
- async reportGood(id) {
138
- const { status, request } = await this.rp.get("res.php", {
139
- searchParams: {
140
- key: this._options.key,
141
- action: "reportgood",
142
- id,
143
- json: 1,
144
- },
145
- });
146
-
147
- if (status === 0) return false;
148
- return true;
149
- }
150
- }