Skip to content

Commit 5032a02

Browse files
Add params checking for Grid method
1 parent 85d42e3 commit 5032a02

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/utils/checkCaptchaParams.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Captcha methods for which parameter checking is available
22
const supportedMethods = ["userrecaptcha", "hcaptcha", "geetest", "geetest_v4","yandex","funcaptcha","lemin","amazon_waf",
3-
"turnstile", "base64", "capy","datadome", "cybersiara", "mt_captcha", "bounding_box", 'friendly_captcha']
3+
"turnstile", "base64", "capy","datadome", "cybersiara", "mt_captcha", "bounding_box", 'friendly_captcha', 'grid']
44

55
// Names of required fields that must be contained in the parameters captcha
66
const recaptchaRequiredFields = ['pageurl','googlekey']
@@ -20,6 +20,7 @@ const сyberSiARARequiredFields = ['pageurl', 'master_url_id', 'userAgent']
2020
const mtСaptchaRequiredFields = ['pageurl', 'sitekey']
2121
const boundingBoxRequiredFields = ['image'] // and textinstructions or imginstructions
2222
const friendlyCaptchaFields = ['pageurl','sitekey']
23+
const gridRequiredFields = ['body'] // and textinstructions or imginstructions
2324

2425
/**
2526
* Getting required arguments for a captcha.
@@ -61,6 +62,9 @@ const getRequiredFildsArr = (method: string):Array<string> => {
6162
case "base64":
6263
requiredFieldsArr = base64RequiredFields
6364
break;
65+
case "grid":
66+
requiredFieldsArr = gridRequiredFields
67+
break;
6468
case "capy":
6569
requiredFieldsArr = capyPuzzleRequiredFields
6670
break;
@@ -116,7 +120,16 @@ export default function checkCaptchaParams(params: Object, method: string) {
116120
isCorrectCaptchaParams = true
117121
} else {
118122
isCorrectCaptchaParams = false
119-
throw new Error(`Error when check params captcha.\nNot found "textinstructions" or "imginstructions" field in the Object. One of this field is required for "bounding_box" method. Please add field "textinstructions" or "imginstructions" in object and try again.\nPlease correct your code for the "bounding_box" method according to the code examples`)
123+
throw new Error(`Error when check params captcha.\nNot found "textinstructions" or "imginstructions" field in the Object. One of this field is required for "bounding_box" method. Please add field "textinstructions" or "imginstructions" in object and try again.\nPlease correct your code for the "bounding_box" method according to the code examples.`)
124+
}
125+
}
126+
127+
if(method === "grid") {
128+
if(params.hasOwnProperty('textinstructions') || params.hasOwnProperty('imginstructions')) {
129+
isCorrectCaptchaParams = true
130+
} else {
131+
isCorrectCaptchaParams = false
132+
throw new Error(`Error when check params captcha.\nNot found "textinstructions" or "imginstructions" field in the Object. One of this field is required for "Grid" method. Please add field "textinstructions" or "imginstructions" in object and try again.\nPlease correct your code for the "Grid" method according to the code examples.`)
120133
}
121134
}
122135

0 commit comments

Comments
 (0)