Skip to main content

px_captcha/
lib.rs

1use async_trait::async_trait;
2use px_errors::AppError;
3use px_pipeline::{ChallengeHandler, HandlerOutcome, PageHtml};
4
5pub struct CaptchaHandler;
6
7impl CaptchaHandler {
8    pub fn new() -> Self {
9        Self
10    }
11}
12
13impl Default for CaptchaHandler {
14    fn default() -> Self {
15        Self::new()
16    }
17}
18
19#[async_trait]
20impl ChallengeHandler for CaptchaHandler {
21    fn name(&self) -> &'static str {
22        "captcha"
23    }
24
25    async fn detects(&self, page: &PageHtml) -> Result<bool, AppError> {
26        let h = &page.html;
27        Ok(h.contains("hcaptcha.com/1/api.js")
28            || h.contains("recaptcha/api.js")
29            || h.contains("class=\"h-captcha\"")
30            || h.contains("class=\"g-recaptcha\""))
31    }
32
33    async fn solve(&self, _page: &PageHtml) -> Result<HandlerOutcome, AppError> {
34        Ok(HandlerOutcome::not_implemented(self.name()))
35    }
36}