Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capsolver #13

Merged
merged 2 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion capsolver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const reCaptchaV3Request = new ReCaptchaV3EnterpriseTask({

```
### Features
* Supports all captcha types, solutions and methods from CapSolver docs (updated at May 2024)
* Supports all captcha types, solutions and methods from CapSolver docs (updated at June 2024)
* TypeScript-first design
* Automatically waits for solution
* Fully tested task payloads
Expand All @@ -94,6 +94,7 @@ What 'custom' does mean? Custom means that the parameters and solutions have bee
* [FunCaptchaClassification](https://docs.capsolver.com/guide/recognition/FunCaptchaClassification.html)
* [ReCaptchaClassification](https://docs.capsolver.com/guide/recognition/ReCaptchaClassification.html)
* [AwsWafClassification](https://docs.capsolver.com/guide/recognition/AwsWafClassification.html)
* [VisionEngine](https://docs.capsolver.com/guide/recognition/VisionEngine.html)
2. Token
* [HCaptchaTask | HCaptchaTaskProxyLess](https://docs.capsolver.com/guide/captcha/HCaptcha.html)
* [FunCaptchaTaskProxyLess](https://docs.capsolver.com/guide/captcha/FunCaptcha.html)
Expand Down
4 changes: 2 additions & 2 deletions capsolver/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 17 additions & 17 deletions capsolver/package.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
{
"name": "@captcha-libs/capsolver",
"version": "1.1.5",
"version": "1.1.7",
"keywords": [
"CapSolver",
"Captcha recognition",
"Captcha solving",
"ReCaptcha captcha",
"DataDome captcha",
"HCaptcha captcha",
"GeeTest captcha",
"MtCaptcha",
"AWS WAF captcha",
"Cloudflare captcha"
"CapSolver",
"Captcha recognition",
"Captcha solving",
"ReCaptcha captcha",
"DataDome captcha",
"HCaptcha captcha",
"GeeTest captcha",
"MtCaptcha",
"AWS WAF captcha",
"Cloudflare captcha"
],
"license": "ISC",
"author": "Max Shy",
"repository": {
"type": "git",
"url": "https://github.com/blackravenx/captcha-libs.git",
"directory": "capsolver"
"type": "git",
"url": "https://github.com/blackravenx/captcha-libs.git",
"directory": "capsolver"
},
"dependencies": {
"@captcha-libs/captcha-client": "latest",
"ofetch": "^1.3.3"
"@captcha-libs/captcha-client": "latest",
"ofetch": "^1.3.3"
},
"description": "CapSolver NodeJS client, captcha recognition service"
}
}
79 changes: 79 additions & 0 deletions capsolver/src/lib/Requests/Classification/VisionEngine.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import type { _IsTaskType } from "../_BaseTaskRequest";
import { BaseTask } from "../_BaseTaskRequest";

const _VisionEngineModules = [
"slider_1",
"rotate_1",
"space_detection"
] as const;

type VisionEngineModules = typeof _VisionEngineModules[number];

interface VisionEngineParams {
image: string;
imageBackground: string;
module: VisionEngineModules;
question?: string;
websiteURL?: string;
}

/**
* @classdesc OCR VisionEngine
* @class
* @extends {BaseTask}
* {@link https://docs.capsolver.com/guide/recognition/VisionEngine.html}
*/
export class VisionEngine extends BaseTask implements VisionEngineParams, _IsTaskType {

/**
* @type {boolean} _isVisionEngine - Only used for correct method overloading intellisense
*/
readonly _isVisionEngine: _IsTaskType["_isVisionEngine"] = true;

/**
* Create VisionEngine
* {@link https://docs.capsolver.com/guide/recognition/VisionEngine.html}
* @param {Object} params - VisionEngineParams
* @param {string} [params.image] - base64 encoded content of the image (no newlines, no data:image/***;charset=utf-8;base64,)
* @param {string} [params.imageBackground] - base64 encoded content of the image (no newlines, no data:image/***;charset=utf-8;base64,)
* @param {string} [params.question] - required for "space_detection" module
* @param {VisionEngineModules=} [params.module] - Specifies the module.
* @param {string} [params.websiteURL] - Page source url to improve accuracy
*/
constructor({
image, imageBackground, question, module, websiteURL
}: VisionEngineParams) {
super({ type: "VisionEngine" });
this.image = image;
this.imageBackground = imageBackground;
this.question = question;
this.module = module;
this.websiteURL = websiteURL;
}

/**
* @type {string} image - base64 encoded content of the image (no newlines, no data:image/***;charset=utf-8;base64,)
*/
image: string;

/**
* @type {string} image - base64 encoded content of the image (no newlines, no data:image/***;charset=utf-8;base64,)
*/
imageBackground: string;

/**
* @type {VisionEngineModules=} module - Specifies the module
* {@see https://docs.capsolver.com/guide/recognition/VisionEngine.html}
*/
module: VisionEngineModules;

/**
* @param {string} question - required for "space_detection" module
*/
question?: string;

/**
* @type {string} websiteURL - Page source url to improve accuracy
*/
websiteURL?: string;
}
14 changes: 8 additions & 6 deletions capsolver/src/lib/Requests/Classification/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import type { AwsWafClassification } from "./AwsWafClassification";
import type { FunCaptchaClassification } from "./FunCaptchaClassification";
import type { HCaptchaClassification } from "./HCaptchaClassification";
import type { ImageToTextTask } from "./ImageToTextTask";
import type { ReCaptchaV2Classification } from "./ReCaptchaV2Classification";
import { AwsWafClassification } from "./AwsWafClassification";
import { FunCaptchaClassification } from "./FunCaptchaClassification";
import { HCaptchaClassification } from "./HCaptchaClassification";
import { ImageToTextTask } from "./ImageToTextTask";
import { ReCaptchaV2Classification } from "./ReCaptchaV2Classification";
import { VisionEngine } from "./VisionEngine";

export {
AwsWafClassification,
FunCaptchaClassification,
HCaptchaClassification,
ImageToTextTask,
ReCaptchaV2Classification
ReCaptchaV2Classification,
VisionEngine
};
3 changes: 2 additions & 1 deletion capsolver/src/lib/Requests/_BaseTaskRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ const _TaskTypes = [
"HCaptchaTaskProxyLess",
"FunCaptchaTaskProxyLess",
"GeeTestTask",
"GeeTestTaskProxyLess"
"GeeTestTaskProxyLess",
"VisionEngine"
] as const;

export type TaskTypes = typeof _TaskTypes[number];
Expand Down
5 changes: 3 additions & 2 deletions capsolver/src/lib/Requests/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import type {
FunCaptchaClassification,
HCaptchaClassification,
ImageToTextTask,
ReCaptchaV2Classification
ReCaptchaV2Classification,
VisionEngine
} from "./Classification";
import type {
AntiAkamaiPowTask, AntiAkamaiBMPTask, AntiAkamaiSensorTask, AntiAkamaiWebTask, AntiAwsWafTask, AntiAwsWafTaskProxyLess, AntiCloudflareChallengeTask, AntiCloudflareTurnstileTask, AntiCyberSiAraTask, AntiCyberSiAraTaskProxyLess, AntiImpervaTask, AntiImpervaTaskProxyLess, DataDomeSliderTask, FunCaptchaTaskProxyLess, GeeTestTask, GeeTestTaskProxyLess, GeeTestV3Task, GeeTestV3TaskProxyLess, GeeTestV4Task, GeeTestV4TaskProxyLess, HCaptchaTask, HCaptchaTaskProxyLess, MtCaptchaTask, MtCaptchaTaskProxyLess, ReCaptchaV2EnterpriseTask, ReCaptchaV2EnterpriseTaskProxyLess, ReCaptchaV2Task, ReCaptchaV2TaskProxyLess, ReCaptchaV3EnterpriseTask, ReCaptchaV3EnterpriseTaskProxyLess, ReCaptchaV3M1TaskProxyLess, ReCaptchaV3Task, ReCaptchaV3TaskProxyLess
} from "./Token";

export type Requests = AntiAkamaiBMPTask | AntiAkamaiPowTask | AntiAkamaiSensorTask | AntiAkamaiWebTask | AntiAwsWafTask | AntiAwsWafTaskProxyLess | AntiCloudflareChallengeTask | AntiCloudflareTurnstileTask | AntiCyberSiAraTask | AntiCyberSiAraTaskProxyLess | AntiImpervaTask | AntiImpervaTaskProxyLess | AwsWafClassification | DataDomeSliderTask | FunCaptchaClassification | FunCaptchaTaskProxyLess | GeeTestTask | GeeTestTaskProxyLess | GeeTestV3Task | GeeTestV3TaskProxyLess | GeeTestV4Task | GeeTestV4TaskProxyLess | HCaptchaClassification | HCaptchaTask | HCaptchaTaskProxyLess | ImageToTextTask | MtCaptchaTask | MtCaptchaTaskProxyLess | ReCaptchaV2Classification | ReCaptchaV2EnterpriseTask | ReCaptchaV2EnterpriseTaskProxyLess | ReCaptchaV2Task | ReCaptchaV2TaskProxyLess | ReCaptchaV3EnterpriseTask | ReCaptchaV3EnterpriseTaskProxyLess | ReCaptchaV3M1TaskProxyLess | ReCaptchaV3Task | ReCaptchaV3TaskProxyLess;
export type Requests = AntiAkamaiBMPTask | AntiAkamaiPowTask | AntiAkamaiSensorTask | AntiAkamaiWebTask | AntiAwsWafTask | AntiAwsWafTaskProxyLess | AntiCloudflareChallengeTask | AntiCloudflareTurnstileTask | AntiCyberSiAraTask | AntiCyberSiAraTaskProxyLess | AntiImpervaTask | AntiImpervaTaskProxyLess | AwsWafClassification | DataDomeSliderTask | FunCaptchaClassification | FunCaptchaTaskProxyLess | GeeTestTask | GeeTestTaskProxyLess | GeeTestV3Task | GeeTestV3TaskProxyLess | GeeTestV4Task | GeeTestV4TaskProxyLess | HCaptchaClassification | HCaptchaTask | HCaptchaTaskProxyLess | ImageToTextTask | MtCaptchaTask | MtCaptchaTaskProxyLess | ReCaptchaV2Classification | ReCaptchaV2EnterpriseTask | ReCaptchaV2EnterpriseTaskProxyLess | ReCaptchaV2Task | ReCaptchaV2TaskProxyLess | ReCaptchaV3EnterpriseTask | ReCaptchaV3EnterpriseTaskProxyLess | ReCaptchaV3M1TaskProxyLess | ReCaptchaV3Task | ReCaptchaV3TaskProxyLess | VisionEngine;

export * from "./Classification";

Expand Down
17 changes: 17 additions & 0 deletions capsolver/src/lib/Solution/Classification/VisionEngineSolution.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

interface VisionEngineAngleSolution {
angle: number;
}

interface VisionEngineDistanceSolution {
distance: number;
}

interface VisionEngineSpaceDetectionSolution {
box: number[];
}

/**
* {@link https://docs.capsolver.com/guide/recognition/VisionEngine.html#example-response}
*/
export type VisionEngineSolution = VisionEngineAngleSolution & VisionEngineDistanceSolution & VisionEngineSpaceDetectionSolution;
14 changes: 8 additions & 6 deletions capsolver/src/lib/Solution/Classification/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import type { AwsWafClassificationSolution } from "./AwsWafClassificationSolution";
import type { FunCaptchaClassificationSolution } from "./FunCaptchaClassificationSolution";
import type { HCaptchaClassificationSolution } from "./HCaptchaClassificationSolution";
import type { ImageToTextSolution } from "./ImageToTextSolution";
import type { ReCaptchaV2ClassificationSolution } from "./ReCaptchaV2ClassificationSolution";
import { VisionEngineSolution } from "./VisionEngineSolution";
import { AwsWafClassificationSolution } from "./AwsWafClassificationSolution";
import { FunCaptchaClassificationSolution } from "./FunCaptchaClassificationSolution";
import { HCaptchaClassificationSolution } from "./HCaptchaClassificationSolution";
import { ImageToTextSolution } from "./ImageToTextSolution";
import { ReCaptchaV2ClassificationSolution } from "./ReCaptchaV2ClassificationSolution";

export {
AwsWafClassificationSolution,
FunCaptchaClassificationSolution,
HCaptchaClassificationSolution,
ImageToTextSolution,
ReCaptchaV2ClassificationSolution
ReCaptchaV2ClassificationSolution,
VisionEngineSolution
};
13 changes: 11 additions & 2 deletions capsolver/src/lib/capsolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ import type {
HCaptchaClassificationSolution,
ImageToTextSolution,
ReCaptchaV2ClassificationSolution,
FunCaptchaClassificationSolution
FunCaptchaClassificationSolution,
VisionEngineSolution
} from "./Solution";
import type {
AntiAkamaiPowTask,
Expand Down Expand Up @@ -69,7 +70,8 @@ import type {
AwsWafClassification,
HCaptchaClassification,
ImageToTextTask,
ReCaptchaV2Classification
ReCaptchaV2Classification,
VisionEngine
} from "./Requests";
import type { CapSolverSolution } from "./Solution/_BaseSolution";
process.removeAllListeners("warning");
Expand Down Expand Up @@ -323,6 +325,12 @@ export class CapSolver extends CaptchaClient<CapSolverCreateTaskResponse, Reques
*/
public async solve(request: FunCaptchaClassification): Promise<CapSolverSolution<FunCaptchaClassificationSolution>>;

/**
* @param {VisionEngine} request - task payload to create task
* @return {Promise<CapSolverSolution<VisionEngineSolution>>} - response of createTask
*/
public async solve(request: VisionEngine): Promise<CapSolverSolution<VisionEngineSolution>>;

/**
* @param {Requests} request - task payload to create task
* @return {Promise<CapSolverSolution<TSolution>>} - response of createTask
Expand Down Expand Up @@ -372,6 +380,7 @@ export class CapSolver extends CaptchaClient<CapSolverCreateTaskResponse, Reques
_isReCaptchaV3M1TaskProxyLess = false,
_isReCaptchaV3Task = false,
_isReCaptchaV3TaskProxyLess = false,
_isVisionEngine = false,
...payload
} = { ...request };

Expand Down
42 changes: 42 additions & 0 deletions capsolver/src/tests/Requests/Classification/VisionEngine.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { VisionEngine } from "../../../lib/Requests/Classification/VisionEngine";

describe("VisionEngine Test", () => {
it("To be equal to object", () => {
const task = new VisionEngine({
image: "image-base64",
imageBackground: "imageBackground-base64",
module: "rotate_1",
question: "question",
websiteURL: "https://some-url.com"
});

expect(task).toEqual({
_endpoint: "createTask",
_isVisionEngine: true,
image: "image-base64",
imageBackground: "imageBackground-base64",
module: "rotate_1",
question: "question",
type: "VisionEngine",
websiteURL: "https://some-url.com"
});
});
it("To be equal to object without optional params", () => {
const task = new VisionEngine({
image: "image-base64",
imageBackground: "imageBackground-base64",
module: "rotate_1"
});

expect(task).toEqual({
_endpoint: "createTask",
_isVisionEngine: true,
image: "image-base64",
imageBackground: "imageBackground-base64",
module: "rotate_1",
question: undefined,
type: "VisionEngine",
websiteURL: undefined
});
});
});
Loading