Skip to content

Commit

Permalink
refactor captcha parameter check
Browse files Browse the repository at this point in the history
  • Loading branch information
dzmitry-duboyski committed Oct 25, 2024
1 parent 2529345 commit 7df649b
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions src/utils/checkCaptchaParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const boundingBoxRequiredFields = ['image'] // and textinstructions or imginstru
const friendlyCaptchaFields = ['pageurl','sitekey']
const gridRequiredFields = ['body'] // and textinstructions or imginstructions
const textCaptchaRequiredFields = ['textcaptcha']
const canvasRequiredFields = ['body'] // надо проверку, если какая нибудь инструкция текст\картинка
const canvasRequiredFields = ['body'] // and textinstructions or imginstructions
const rotateRequiredFields = ['body']

/**
Expand Down Expand Up @@ -127,21 +127,13 @@ export default function checkCaptchaParams(params: Object, method: string) {
}
})

if(method === "bounding_box") {
//The parameters `textinstructions` and `imginstructions` are mandatory for the methods `bounding_box`, `grid`, and `canvas`.
if(method === "bounding_box" || method === "grid" || method === "canvas") {
if(params.hasOwnProperty('textinstructions') || params.hasOwnProperty('imginstructions')) {
isCorrectCaptchaParams = true
} else {
isCorrectCaptchaParams = false
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.`)
}
}

if(method === "grid") {
if(params.hasOwnProperty('textinstructions') || params.hasOwnProperty('imginstructions')) {
isCorrectCaptchaParams = true
} else {
isCorrectCaptchaParams = false
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.`)
throw new Error(`Error when check params captcha.\nNot found "textinstructions" or "imginstructions" field in the Object. One of this field is required for "${method}" method. Please add field "textinstructions" or "imginstructions" to captcha parameters.`)
}
}

Expand Down

0 comments on commit 7df649b

Please sign in to comment.