mirror of
https://github.com/FlareSolverr/FlareSolverr.git
synced 2026-04-23 00:15:36 +02:00
Backport changes from Cloudproxy (#11)
This commit is contained in:
31
src/captcha/harvester.ts
Normal file
31
src/captcha/harvester.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import got from 'got'
|
||||
import { sleep } from '../utils'
|
||||
|
||||
/*
|
||||
This method uses the captcha-harvester project:
|
||||
https://github.com/NoahCardoza/CaptchaHarvester
|
||||
|
||||
While the function must take url/sitekey/type args,
|
||||
they aren't used because the harvester server must
|
||||
be preconfigured.
|
||||
|
||||
ENV:
|
||||
HARVESTER_ENDPOINT: This must be the full path
|
||||
to the /token endpoint of the harvester.
|
||||
E.G. "https://127.0.0.1:5000/token"
|
||||
*/
|
||||
|
||||
export default async function solve(): Promise<string> {
|
||||
const endpoint = process.env.HARVESTER_ENDPOINT
|
||||
if (!endpoint) { throw Error('ENV variable `HARVESTER_ENDPOINT` must be set.') }
|
||||
while (true) {
|
||||
try {
|
||||
return (await got.get(process.env.HARVESTER_ENDPOINT, {
|
||||
https: { rejectUnauthorized: false }
|
||||
})).body
|
||||
} catch (e) {
|
||||
if (e.response.statusCode !== 418) { throw e }
|
||||
}
|
||||
await sleep(3000)
|
||||
}
|
||||
}
|
||||
21
src/captcha/hcaptcha-solver.ts
Normal file
21
src/captcha/hcaptcha-solver.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
const solveCaptcha = require('hcaptcha-solver');
|
||||
import { SolverOptions } from '.'
|
||||
/*
|
||||
This method uses the hcaptcha-solver project:
|
||||
https://github.com/JimmyLaurent/hcaptcha-solver
|
||||
|
||||
TODO: allow user pass custom options to the solver.
|
||||
|
||||
ENV:
|
||||
There are no other variables that must be set to get this to work
|
||||
*/
|
||||
|
||||
export default async function solve({ url }: SolverOptions): Promise<string> {
|
||||
try {
|
||||
const token = await solveCaptcha(url)
|
||||
return token
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
return null
|
||||
}
|
||||
}
|
||||
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