Skip to content
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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ All notable changes to this crate are documented here. The format follows
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/), versions follow [SemVer](https://semver.org/)
(while the major version is 0, a breaking change bumps the **minor** number).

## [0.2.0]

### Added
- `FengkongCloudRequest` (`CustomTask`, class `fengkongcloud`).
- `ArCaptchaRequest` (`ArCaptchaTask`).
- `HeyTapRequest` (`CustomTask`, class `heytap`).
- `ProtonRequest` (`CustomTask`, class `proton`, proxy required).

## [0.1.2]

### Added
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "capmonstercloud-client"
version = "0.1.2"
version = "0.2.0"
edition = "2021"
rust-version = "1.88"
description = "Async Rust client for the CapMonster Cloud captcha-solving API"
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,8 @@ All task types follow the official [CapMonster Cloud API documentation](https://
| **TSPD** | `TspdCustomTaskRequest` | 🌐 Required |
| **HUNT** | `HuntCustomTaskRequest` | 🌐 Required |
| **Basilisk / TenDI / Alibaba / Friendly Captcha / Altcha** | `BasiliskCustomTaskRequest`, `TenDiCustomTaskRequest`, `AlibabaCustomTaskRequest`, `FriendlyCustomTaskRequest`, `AltchaCustomTaskRequest` | Optional |
| **Proton Captcha** | `ProtonRequest` | 🌐 Required |
| **FengkongCloud / ARCaptcha / HeyTap** | `FengkongCloudRequest`, `ArCaptchaRequest`, `HeyTapRequest` | — |
| **Binance CAPTCHA** | `BinanceTaskRequest` | Optional |
| **MTCaptcha / Yidun / Prosopo** | `MtCaptchaRequest`, `YidunRequest`, `ProsopoTaskRequest` | Optional |
| **Standard Text CAPTCHA** | `ImageToTextRequest` (+ `TextModule`) | — |
Expand Down
104 changes: 104 additions & 0 deletions src/requests/arcaptcha.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
use serde::Serialize;

use super::{require_non_empty, CaptchaRequest};
use crate::error::Result;
use crate::timeouts::GetResultTimeouts;

/// ARCaptcha (`ArCaptchaTask`). The solution token is in `solution.token`.
#[derive(Debug, Clone, Serialize)]
pub struct ArCaptchaRequest {
/// The address of the main page where the captcha is located.
#[serde(rename = "websiteURL")]
pub website_url: String,
/// The siteKey value found on the page.
#[serde(rename = "websiteKey")]
pub website_key: String,
/// `true` if the captcha is invisible (has a hidden verification field).
#[serde(rename = "isInvisible", skip_serializing_if = "Option::is_none")]
pub is_invisible: Option<bool>,
/// Browser User-Agent (current Windows UA supported by CapMonster Cloud).
#[serde(rename = "userAgent", skip_serializing_if = "Option::is_none")]
pub user_agent: Option<String>,
}

impl ArCaptchaRequest {
pub fn new(website_url: impl Into<String>, website_key: impl Into<String>) -> Self {
Self {
website_url: website_url.into(),
website_key: website_key.into(),
is_invisible: None,
user_agent: None,
}
}

pub fn with_is_invisible(mut self, value: bool) -> Self {
self.is_invisible = Some(value);
self
}

pub fn with_user_agent(mut self, value: impl Into<String>) -> Self {
self.user_agent = Some(value.into());
self
}
}

impl CaptchaRequest for ArCaptchaRequest {
const TASK_TYPE: &'static str = "ArCaptchaTask";

fn timeouts(&self) -> GetResultTimeouts {
GetResultTimeouts::secs(1.0, 0.0, 3.0, 180.0)
}

fn validate(&self) -> Result<()> {
require_non_empty("websiteURL", &self.website_url)?;
require_non_empty("websiteKey", &self.website_key)?;
Ok(())
}
}

#[cfg(test)]
mod tests {
use super::*;
use serde_json::json;

#[test]
fn minimal_task() {
let task = ArCaptchaRequest::new("https://example.com", "KEY")
.to_task()
.unwrap();
assert_eq!(
task,
json!({
"type": "ArCaptchaTask",
"websiteURL": "https://example.com", "websiteKey": "KEY"
})
);
}

#[test]
fn full_task() {
let task = ArCaptchaRequest::new("https://example.com", "KEY")
.with_is_invisible(false)
.with_user_agent("UA")
.to_task()
.unwrap();
assert_eq!(
task,
json!({
"type": "ArCaptchaTask",
"websiteURL": "https://example.com", "websiteKey": "KEY",
"isInvisible": false, "userAgent": "UA"
})
);
}

#[test]
fn empty_required_strings_are_rejected() {
let err = ArCaptchaRequest::new("", "KEY").to_task().unwrap_err();
assert!(matches!(err, crate::error::Error::Validation(ref m) if m.contains("websiteURL")));
let err = ArCaptchaRequest::new("https://example.com", "")
.to_task()
.unwrap_err();
assert!(matches!(err, crate::error::Error::Validation(ref m) if m.contains("websiteKey")));
}
}
118 changes: 118 additions & 0 deletions src/requests/fengkongcloud.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
use serde::Serialize;

use super::{require_non_empty, CaptchaRequest};
use crate::error::Result;
use crate::timeouts::GetResultTimeouts;

/// FengkongCloud-specific data (`metadata`).
#[derive(Debug, Clone, Serialize)]
pub struct FengkongCloudMetadata {
/// Link to `smcp.min.js`, e.g. `https://example.com/pr/vX.X.X/smcp.min.js`.
#[serde(rename = "apiJsUrl", skip_serializing_if = "Option::is_none")]
pub api_js_url: Option<String>,
}

/// FengkongCloud captcha (`CustomTask`, class `fengkongcloud`). The solution token is in
/// `solution.data.token`.
#[derive(Debug, Clone, Serialize)]
pub struct FengkongCloudRequest {
/// The address of the main page where the captcha is located.
#[serde(rename = "websiteURL")]
pub website_url: String,
/// The `appid` value found on the page.
#[serde(rename = "websiteKey")]
pub website_key: String,
/// Optional challenge data; sent only when `api_js_url` is set.
#[serde(skip_serializing_if = "Option::is_none")]
pub metadata: Option<FengkongCloudMetadata>,
/// Browser User-Agent (current Windows UA supported by CapMonster Cloud).
#[serde(rename = "userAgent", skip_serializing_if = "Option::is_none")]
pub user_agent: Option<String>,
}

impl FengkongCloudRequest {
pub fn new(website_url: impl Into<String>, website_key: impl Into<String>) -> Self {
Self {
website_url: website_url.into(),
website_key: website_key.into(),
metadata: None,
user_agent: None,
}
}

/// Sets `metadata.apiJsUrl`, the link to `smcp.min.js`.
pub fn with_api_js_url(mut self, value: impl Into<String>) -> Self {
self.metadata = Some(FengkongCloudMetadata {
api_js_url: Some(value.into()),
});
self
}

pub fn with_user_agent(mut self, value: impl Into<String>) -> Self {
self.user_agent = Some(value.into());
self
}
}

impl CaptchaRequest for FengkongCloudRequest {
const TASK_TYPE: &'static str = "CustomTask";
const CLASS: Option<&'static str> = Some("fengkongcloud");

fn timeouts(&self) -> GetResultTimeouts {
GetResultTimeouts::secs(1.0, 0.0, 3.0, 180.0)
}

fn validate(&self) -> Result<()> {
require_non_empty("websiteURL", &self.website_url)?;
require_non_empty("websiteKey", &self.website_key)?;
Ok(())
}
}

#[cfg(test)]
mod tests {
use super::*;
use serde_json::json;

#[test]
fn minimal_task() {
let task = FengkongCloudRequest::new("https://example.com", "KEY")
.to_task()
.unwrap();
assert_eq!(
task,
json!({
"type": "CustomTask", "class": "fengkongcloud",
"websiteURL": "https://example.com", "websiteKey": "KEY"
})
);
}

#[test]
fn full_task() {
let task = FengkongCloudRequest::new("https://example.com", "KEY")
.with_api_js_url("https://example.com/smcp.min.js")
.with_user_agent("UA")
.to_task()
.unwrap();
assert_eq!(
task,
json!({
"type": "CustomTask", "class": "fengkongcloud",
"websiteURL": "https://example.com", "websiteKey": "KEY",
"metadata": {"apiJsUrl": "https://example.com/smcp.min.js"},
"userAgent": "UA"
})
);
}

#[test]
fn empty_required_strings_are_rejected() {
let err = FengkongCloudRequest::new("", "KEY").to_task().unwrap_err();
assert!(matches!(err, crate::error::Error::Validation(ref m) if m.contains("websiteURL")));
let err = FengkongCloudRequest::new("https://example.com", "")
.to_task()
.unwrap_err();
assert!(matches!(err, crate::error::Error::Validation(ref m) if m.contains("websiteKey")));
}
}
119 changes: 119 additions & 0 deletions src/requests/heytap.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
use serde::Serialize;

use super::{require_non_empty, CaptchaRequest};
use crate::error::Result;
use crate::timeouts::GetResultTimeouts;

/// HeyTap-specific data (`metadata`).
#[derive(Debug, Clone, Serialize)]
pub struct HeyTapMetadata {
/// Subdomain of the HeyTap API server, without the `https://` prefix. Must be specified
/// when it differs from the default server.
#[serde(rename = "apiServer", skip_serializing_if = "Option::is_none")]
pub api_server: Option<String>,
}

/// HeyTap captcha (`CustomTask`, class `heytap`). The solution token is in
/// `solution.data.token`.
#[derive(Debug, Clone, Serialize)]
pub struct HeyTapRequest {
/// The address of the main page where the captcha is located.
#[serde(rename = "websiteURL")]
pub website_url: String,
/// The siteKey value found on the page (the `ak` parameter of the HeyTap API URL).
#[serde(rename = "websiteKey")]
pub website_key: String,
/// Optional challenge data; sent only when `api_server` is set.
#[serde(skip_serializing_if = "Option::is_none")]
pub metadata: Option<HeyTapMetadata>,
/// Browser User-Agent (current Windows UA supported by CapMonster Cloud).
#[serde(rename = "userAgent", skip_serializing_if = "Option::is_none")]
pub user_agent: Option<String>,
}

impl HeyTapRequest {
pub fn new(website_url: impl Into<String>, website_key: impl Into<String>) -> Self {
Self {
website_url: website_url.into(),
website_key: website_key.into(),
metadata: None,
user_agent: None,
}
}

/// Sets `metadata.apiServer` (domain only, without `https://`).
pub fn with_api_server(mut self, value: impl Into<String>) -> Self {
self.metadata = Some(HeyTapMetadata {
api_server: Some(value.into()),
});
self
}

pub fn with_user_agent(mut self, value: impl Into<String>) -> Self {
self.user_agent = Some(value.into());
self
}
}

impl CaptchaRequest for HeyTapRequest {
const TASK_TYPE: &'static str = "CustomTask";
const CLASS: Option<&'static str> = Some("heytap");

fn timeouts(&self) -> GetResultTimeouts {
GetResultTimeouts::secs(1.0, 0.0, 3.0, 180.0)
}

fn validate(&self) -> Result<()> {
require_non_empty("websiteURL", &self.website_url)?;
require_non_empty("websiteKey", &self.website_key)?;
Ok(())
}
}

#[cfg(test)]
mod tests {
use super::*;
use serde_json::json;

#[test]
fn minimal_task() {
let task = HeyTapRequest::new("https://example.com", "KEY")
.to_task()
.unwrap();
assert_eq!(
task,
json!({
"type": "CustomTask", "class": "heytap",
"websiteURL": "https://example.com", "websiteKey": "KEY"
})
);
}

#[test]
fn full_task() {
let task = HeyTapRequest::new("https://example.com", "KEY")
.with_api_server("api.example.com")
.with_user_agent("UA")
.to_task()
.unwrap();
assert_eq!(
task,
json!({
"type": "CustomTask", "class": "heytap",
"websiteURL": "https://example.com", "websiteKey": "KEY",
"metadata": {"apiServer": "api.example.com"},
"userAgent": "UA"
})
);
}

#[test]
fn empty_required_strings_are_rejected() {
let err = HeyTapRequest::new("", "KEY").to_task().unwrap_err();
assert!(matches!(err, crate::error::Error::Validation(ref m) if m.contains("websiteURL")));
let err = HeyTapRequest::new("https://example.com", "")
.to_task()
.unwrap_err();
assert!(matches!(err, crate::error::Error::Validation(ref m) if m.contains("websiteKey")));
}
}
Loading
Loading