mirror of
https://github.com/FlareSolverr/FlareSolverr.git
synced 2025-12-09 11:08:39 +01:00
Backport changes from Cloudproxy (#11)
This commit is contained in:
35
src/captcha/index.ts
Normal file
35
src/captcha/index.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
export enum CaptchaType {
|
||||
re = 'reCaptcha',
|
||||
h = 'hCaptcha'
|
||||
}
|
||||
|
||||
export interface SolverOptions {
|
||||
url: string
|
||||
sitekey: string
|
||||
type: CaptchaType
|
||||
}
|
||||
|
||||
export type Solver = (options: SolverOptions) => Promise<string>
|
||||
|
||||
const captchaSolvers: { [key: string]: Solver } = {}
|
||||
|
||||
export default (): Solver => {
|
||||
const method = process.env.CAPTCHA_SOLVER
|
||||
|
||||
if (!method) { return null }
|
||||
|
||||
if (!(method in captchaSolvers)) {
|
||||
try {
|
||||
captchaSolvers[method] = require('./' + method).default as Solver
|
||||
} catch (e) {
|
||||
if (e.code === 'MODULE_NOT_FOUND') {
|
||||
throw Error(`The solver '${method}' is not a valid captcha solving method.`)
|
||||
} else {
|
||||
console.error(e)
|
||||
throw Error(`An error occured loading the solver '${method}'.`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return captchaSolvers[method]
|
||||
}
|
||||
Reference in New Issue
Block a user