Skip to content

Commit 5a2ec5c

Browse files
Refactor
1 parent d2c69ea commit 5a2ec5c

File tree

5 files changed

+49
-71
lines changed

5 files changed

+49
-71
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Examples of API requests for different captcha types are available on the [JavaS
1717
- [Configuration](#configuration)
1818
- [TwoCaptcha instance options](#twocaptcha-instance-options)
1919
- [Solve captcha](#solve-captcha)
20-
- [Image Сaptcha](#image-captcha)
20+
- [Image Captcha](#image-captcha)
2121
- [reCAPTCHA v2](#recaptcha-v2)
2222
- [reCAPTCHA v3](#recaptcha-v3)
2323
- [hCaptcha](#hcaptcha)
File renamed without changes.

examples/tencent.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const solver = new TwoCaptcha.Solver(APIKEY);
55

66
solver.tencent({
77
pageurl: "https://mysite.com/page/with/tencent",
8-
appId: "189956587"
8+
appId: "189956587"
99
})
1010
.then((res) => {
1111
console.log(res);

src/structs/2captcha.ts

Lines changed: 43 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ export interface paramsHCaptcha {
4343
domain?: string
4444
}
4545

46-
// FixMe:data[key] - how to send this parameter
4746
export interface paramsFunCaptcha {
4847
publickey: string,
4948
pageurl: string,
@@ -84,18 +83,6 @@ export interface paramsGeetest {
8483
userAgent?: string
8584
}
8685

87-
/**
88-
* Interface for yandexSmart captcha
89-
*
90-
* @typedef {object} yandexSmart
91-
* @property {string} pageurl URL of the page where the captcha is located
92-
* @property {string} sitekey The `sitekey` value you found on the captcha page
93-
* @property {string} pingback
94-
* @property {string} proxy Format: `login:password@123.123.123.123:3128`. You can find more info about proxies [here](https://2captcha.com/2captcha-api#proxies).
95-
* @property {string} proxytype Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
96-
* @property {string} userAgent Your `userAgent` that will be passed to our worker and used to solve the captcha.
97-
*
98-
*/
9986
export interface yandexSmart {
10087
pageurl: string,
10188
sitekey: string,
@@ -105,18 +92,6 @@ export interface yandexSmart {
10592
userAgent?: string
10693
}
10794

108-
/**
109-
* Interface for GeeTest V4 captcha
110-
*
111-
* @typedef {object} paramsGeeTestV4
112-
* @property {string} pageurl Required parameter. URL of the page where the captcha is located
113-
* @property {string} captcha_id Required parameter. Value of `captcha_id` parameter you found on target website.
114-
* @property {string} pingback An optional param. [More info here](https://2captcha.com/2captcha-api#pingback).
115-
* @property {string} proxy An optional param. Format: `login:password@123.123.123.123:3128`
116-
* @property {string} proxytype An optional param. Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
117-
* @property {string} userAgent An optional param. Your `userAgent` that will be passed to our worker and used to solve the captcha.
118-
*
119-
*/
12095
export interface paramsGeeTestV4 {
12196
pageurl: string,
12297
captcha_id: string,
@@ -237,8 +212,8 @@ export interface paramsGrid {
237212
canvas?: number,
238213
rows?: number,
239214
cols?: number,
240-
minСlicks?: number,
241-
maxСlicks?: number,
215+
minClicks?: number,
216+
maxClicks?: number,
242217
previousId?: string,
243218
imgType?: string,
244219
textinstructions?: string,
@@ -960,7 +935,7 @@ export class Solver {
960935
*
961936
* [Read more about Cloudflare Turnstile captcha](https://2captcha.com/2captcha-api#turnstile).
962937
*
963-
* @param {{ pageurl, sitekey, action, data, pingback, proxy, proxytype}} params The `сloudflareTurnstile` method takes arguments as an object. Thus, the `pageurl`, `sitekey` fields in the passed object are mandatory.
938+
* @param {{ pageurl, sitekey, action, data, pingback, proxy, proxytype}} params The `cloudflareTurnstile` method takes arguments as an object. Thus, the `pageurl`, `sitekey` fields in the passed object are mandatory.
964939
* @param {string} params.pageurl Full `URL` of the page where you see the captcha.
965940
* @param {string} params.sitekey Is a value of `sitekey` parameter in the page source.
966941
* @param {string} params.action Value of optional `action` parameter you found on page.
@@ -1009,7 +984,7 @@ export class Solver {
1009984
/**
1010985
* ### Solves a Coordinates captcha.
1011986
*
1012-
* @param {{ body, imginstructions, textinstructions, language, lang, pingback }} params parameters Сoordinates Captcha as an object.
987+
* @param {{ body, imginstructions, textinstructions, language, lang, pingback }} params parameters Coordinates Captcha as an object.
1013988
* @param {string} params.body Base64-encoded captcha image.
1014989
* @param {string} params.imginstructions Base64-encoded image with instruction for solving captcha.
1015990
* @param {string} params.textinstructions Text will be shown to worker to help him to solve the captcha correctly. For example: click on all objects in red color.
@@ -1266,35 +1241,35 @@ public async mtCaptcha(params: paramsMTCaptcha): Promise<CaptchaAnswer> {
12661241
}
12671242

12681243
/**
1269-
* ### Solves a Cutcaptcha.
1270-
*
1271-
* Use this method to solve Cutcaptcha. Returns the response in JSON.
1272-
* [Read more about Cutcaptcha](https://2captcha.com/2captcha-api#Cutcaptcha).
1273-
*
1274-
* @param {{ pageurl, miseryKey, apiKey, pingback, proxy, proxytype }} params Parameters for solving Cutcaptcha as an object.
1275-
* @param {string} params.pageurl The URL where the captcha is located.
1276-
* @param {string} params.miseryKey The value of `CUTCAPTCHA_MISERY_KEY` variable defined on page.
1277-
* @param {string} params.apiKey The value of `data-apikey` attribute of iframe's body. Also the name of javascript file included on the page
1278-
* @param {string} [params.pingback] Optional param. URL for pingback (callback) response when captcha is solved.
1279-
* @param {string} [params.proxy] Optional param. Proxy to use while solving the captcha. Format: `login:password@123.123.123.123:3128`.
1280-
* @param {string} [params.proxytype] Optional param. Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
1281-
*
1282-
* @returns {Promise<CaptchaAnswer>} The result from the solve.
1283-
* @throws APIError
1284-
*
1285-
* @example
1286-
* solver.cutCaptcha({
1287-
* pageurl: "https://mysite.com/page/with/cutcaptcha",
1288-
* miseryKey: "098e6a849af406142e3150dbf4e6d0538db2b51f",
1289-
* apiKey: "SAs61IAI",
1290-
* })
1291-
* .then((res) => {
1292-
* console.log(res);
1293-
* })
1294-
* .catch((err) => {
1295-
* console.log(err);
1296-
* })
1297-
*/
1244+
* ### Solves a Cutcaptcha.
1245+
*
1246+
* Use this method to solve Cutcaptcha. Returns the response in JSON.
1247+
* [Read more about Cutcaptcha Method](https://2captcha.com/2captcha-api#cutcaptcha).
1248+
*
1249+
* @param {{ pageurl, miseryKey, apiKey, pingback, proxy, proxytype }} params Parameters for solving Cutcaptcha as an object.
1250+
* @param {string} params.pageurl The URL where the captcha is located.
1251+
* @param {string} params.miseryKey The value of `CUTCAPTCHA_MISERY_KEY` variable defined on page.
1252+
* @param {string} params.apiKey The value of `data-apikey` attribute of iframe's body. Also the name of javascript file included on the page
1253+
* @param {string} [params.pingback] Optional param. URL for pingback (callback) response when captcha is solved.
1254+
* @param {string} [params.proxy] Optional param. Proxy to use while solving the captcha. Format: `login:password@123.123.123.123:3128`.
1255+
* @param {string} [params.proxytype] Optional param. Type of your proxy: `HTTP`, `HTTPS`, `SOCKS4`, `SOCKS5`.
1256+
*
1257+
* @returns {Promise<CaptchaAnswer>} The result from the solve.
1258+
* @throws APIError
1259+
*
1260+
* @example
1261+
* solver.cutCaptcha({
1262+
* pageurl: "https://mysite.com/page/with/cutcaptcha",
1263+
* miseryKey: "098e6a849af406142e3150dbf4e6d0538db2b51f",
1264+
* apiKey: "SAs61IAI",
1265+
* })
1266+
* .then((res) => {
1267+
* console.log(res);
1268+
* })
1269+
* .catch((err) => {
1270+
* console.log(err);
1271+
* })
1272+
*/
12981273
public async cutCaptcha(params: paramsCutcaptcha): Promise<CaptchaAnswer> {
12991274
params = renameParams(params)
13001275
checkCaptchaParams(params, "cutcaptcha")
@@ -1432,14 +1407,14 @@ public async boundingBox(params: paramsBoundingBox): Promise<CaptchaAnswer> {
14321407
*
14331408
* The method can be used to bypass tasks where a grid is applied to an image and you need to click on grid tiles, like reCAPTCHA or hCaptcha images.
14341409
*
1435-
* @param {{ body, textinstructions, imginstructions, rows, cols, minСlicks, maxСlicks, imgType, previousId, canSkip, lang, pingback}} params Parameters Grid Method as an object.
1410+
* @param {{ body, textinstructions, imginstructions, rows, cols, minClicks, maxClicks, imgType, previousId, canSkip, lang, pingback}} params Parameters Grid Method as an object.
14361411
* @param {string} params.body `Base64`- encoded captcha image.
14371412
* @param {string} params.textinstructions Text will be shown to worker to help him to select object on the image correctly. For example: "*Select cars in the image*". **Optional parameter**, if the instruction already exists in the form of the `imginstructions`.
14381413
* @param {string} params.imginstructions Image with instruction for worker to help him to select object on the image correctly. The image must be encoded in `Base64` format. **Optional parameter**, if the instruction already exists in the form of the `textinstructions`.
14391414
* @param {number} params.rows Number of rows in grid captcha.
14401415
* @param {number} params.cols Number of columns in grid captcdha.
1441-
* @param {number} params.minСlicks The minimum number of tiles that must be selected. Can't be more than `rows` * `cols`.
1442-
* @param {number} params.maxСlicks The maximum number of tiles that can be selected on the image.
1416+
* @param {number} params.minClicks The minimum number of tiles that must be selected. Can't be more than `rows` * `cols`.
1417+
* @param {number} params.maxClicks The maximum number of tiles that can be selected on the image.
14431418
* @param {string} params.imgType The image will be recognized using Computer Vision. Supported value options: `recaptcha`, `hcaptcha`, `funcaptcha`, `funcaptcha_compare`. [More info here](https://2captcha.com/2captcha-api#grid).
14441419
* @param {string} params.previousId Id of your previous request with the same captcha challenge.
14451420
* @param {number} params.canSkip Set the value to `1` only if it's possible that there's no images matching to the instruction. We'll provide a button "No matching images" to worker and you will receive `No_matching_images` as answer.
@@ -1497,6 +1472,7 @@ public async grid(params: paramsGrid): Promise<CaptchaAnswer> {
14971472
* ### Text Captcha method
14981473
*
14991474
* Text Captcha is a type of captcha that is represented as text and doesn't contain images. Usually you have to answer a question to pass the verification. For example: "If tomorrow is Saturday, what day is today?".
1475+
* [Read more about Text Captcha Method](https://2captcha.com/2captcha-api#text-captcha).
15001476
*
15011477
* @param {{ textcaptcha, lang, pingback}} params Parameters Text Captcha Method as an object.
15021478
* @param {string} params.textcaptcha Text Captcha is a type of captcha that is represented as text and doesn't contain images. Usually you have to answer a question to pass the verification.
@@ -1551,6 +1527,7 @@ public async text(params: paramsTextcaptcha): Promise<CaptchaAnswer> {
15511527
* ### Canvas method
15521528
*
15531529
* This method can be used to bypass tasks in which you need to circle an object or line in an image.
1530+
* [Read more about Canvas Method](https://2captcha.com/2captcha-api#canvas).
15541531
*
15551532
* @param {{ body, textinstructions, imginstructions, canSkip, lang, pingback}} params Parameters Canvas as an object.
15561533
* @param {string} params.body `Base64`- encoded captcha image.
@@ -1612,6 +1589,7 @@ public async canvas(params: paramsGrid): Promise<CaptchaAnswer> {
16121589
* ### Rotate method
16131590
*
16141591
* This method can be used to solve a captcha that asks to rotate an object. It is mostly used to bypass FunCaptcha. Returns the rotation angle.
1592+
* [Read more about Rotate Method](https://2captcha.com/2captcha-api#solving_rotatecaptcha).
16151593
*
16161594
* @param {{ body, angle, pingback, lang, textinstructions, imginstructions }} params Parameters for solving Rotate Captcha as an object.
16171595
* @param {string} params.body Base64-encoded image of the captcha that needs to be rotated.
@@ -1673,7 +1651,7 @@ public async rotate(params: paramsRotateCaptcha): Promise<CaptchaAnswer> {
16731651
* ### Solves a KeyCaptcha.
16741652
*
16751653
* This method can be used to solve a KeyCaptcha. It is mostly used to bypass captchas that use KeyCaptcha technology.
1676-
* [Read more about KeyCaptcha](https://2captcha.com/2captcha-api#solving_keycaptcha).
1654+
* [Read more about KeyCaptcha Method](https://2captcha.com/2captcha-api#solving_keycaptcha).
16771655
*
16781656
* @param {{ pageurl, userId, sessionId, webServerSign, webServerSign2, pingback, proxy, proxytype }} params Parameters for solving KeyCaptcha as an object.
16791657
* @param {string} params.pageurl The URL where the captcha is located.
@@ -1739,7 +1717,7 @@ public async keyCaptcha(params: paramsKeyCaptcha): Promise<CaptchaAnswer> {
17391717
* ### Solves a Tencent.
17401718
*
17411719
* Use this method to solve Tencent captcha. Returns a token.
1742-
* [Read more about Tencent](https://2captcha.com/2captcha-api#tencent).
1720+
* [Read more about Tencent Method](https://2captcha.com/2captcha-api#tencent).
17431721
*
17441722
* @param {{ pageurl, appId, pingback, proxy, proxytype }} params Parameters for solving Tencent as an object.
17451723
* @param {string} params.pageurl The URL where the captcha is located.
@@ -1799,7 +1777,7 @@ public async tencent(params: paramsTencent): Promise<CaptchaAnswer> {
17991777
* ### Solves a atbCAPTCHA.
18001778
*
18011779
* Use this method to solve atbCAPTCHA captcha. Returns a token.
1802-
* [Read more about atbCAPTCHA](https://2captcha.com/2captcha-api#atb-captcha).
1780+
* [Read more about atbCAPTCHA Method](https://2captcha.com/2captcha-api#atb-captcha).
18031781
*
18041782
* @param {{ pageurl, appId, apiServer, pingback, proxy, proxytype }} params Parameters for solving atbCAPTCHA as an object.
18051783
* @param {string} params.pageurl The URL where the captcha is located.
@@ -1862,7 +1840,7 @@ public async atbCaptcha(params: paramsAtbCaptcha): Promise<CaptchaAnswer> {
18621840
* ### Method for solving Audio captcha.
18631841
*
18641842
* Use the following method to bypass an audio captcha (`mp3` formats only). You must provide the language as `lang = 'en'`. Supported languages are "en", "ru", "de", "el", "pt", "fr".
1865-
* [Read more about audio captcha parameters](https://2captcha.com/2captcha-api#audio).
1843+
* [Read more about Audio recognition Method](https://2captcha.com/2captcha-api#audio-recognition).
18661844
*
18671845
* @param {{ body, lang, pingback }} params Object containing parameters for the audio captcha.
18681846
* @param {string} params.body Base64 encoded audio file in `mp3` format. Max file size: 1 MB.

src/utils/checkCaptchaParams.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ const turnstileRequiredFields = ['pageurl','sitekey']
1717
const base64RequiredFields = ['body']
1818
const capyPuzzleRequiredFields = ['captchakey']
1919
const dataDomeRequiredFields = ['pageurl', 'captcha_url', 'userAgent', 'proxy', 'proxytype']
20-
const сyberSiARARequiredFields = ['pageurl', 'master_url_id', 'userAgent']
21-
const mtСaptchaRequiredFields = ['pageurl', 'sitekey']
20+
const cyberSiARARequiredFields = ['pageurl', 'master_url_id', 'userAgent']
21+
const mtCaptchaRequiredFields = ['pageurl', 'sitekey']
2222
const boundingBoxRequiredFields = ['image'] // and textinstructions or imginstructions
2323
const friendlyCaptchaFields = ['pageurl','sitekey']
2424
const gridRequiredFields = ['body'] // and textinstructions or imginstructions
@@ -81,10 +81,10 @@ const getRequiredFildsArr = (method: string):Array<string> => {
8181
requiredFieldsArr = dataDomeRequiredFields
8282
break;
8383
case "cybersiara":
84-
requiredFieldsArr = сyberSiARARequiredFields
84+
requiredFieldsArr = cyberSiARARequiredFields
8585
break;
8686
case "mt_captcha":
87-
requiredFieldsArr = mtСaptchaRequiredFields
87+
requiredFieldsArr = mtCaptchaRequiredFields
8888
break;
8989
case "bounding_box":
9090
requiredFieldsArr = boundingBoxRequiredFields

0 commit comments

Comments
 (0)