mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2025-11-24 06:25:46 +00:00
feat: def interface to get traffic pattern
This commit is contained in:
parent
a6920f5f36
commit
212c03a0e2
@ -44,6 +44,9 @@ pub enum DBError {
|
|||||||
/// Captcha not found
|
/// Captcha not found
|
||||||
#[error("Captcha not found")]
|
#[error("Captcha not found")]
|
||||||
CaptchaNotFound,
|
CaptchaNotFound,
|
||||||
|
/// Traffic pattern not found
|
||||||
|
#[error("Traffic pattern not found")]
|
||||||
|
TrafficPatternNotFound,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Convenience type alias for grouping driver-specific errors
|
/// Convenience type alias for grouping driver-specific errors
|
||||||
|
|||||||
@ -194,9 +194,16 @@ pub trait MCDatabase: std::marker::Send + std::marker::Sync + CloneSPDatabase {
|
|||||||
captcha_key: &str,
|
captcha_key: &str,
|
||||||
pattern: &TrafficPattern,
|
pattern: &TrafficPattern,
|
||||||
) -> DBResult<()>;
|
) -> DBResult<()>;
|
||||||
|
|
||||||
|
/// Get traffic configuration
|
||||||
|
async fn get_traffic_pattern(
|
||||||
|
&self,
|
||||||
|
username: &str,
|
||||||
|
captcha_key: &str,
|
||||||
|
) -> DBResult<TrafficPattern>;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default, Serialize, Deserialize, Clone, Debug)]
|
#[derive(Default, PartialEq, Serialize, Deserialize, Clone, Debug)]
|
||||||
/// User's traffic pattern; used in generating a captcha configuration
|
/// User's traffic pattern; used in generating a captcha configuration
|
||||||
pub struct TrafficPattern {
|
pub struct TrafficPattern {
|
||||||
/// average traffic of user's website
|
/// average traffic of user's website
|
||||||
|
|||||||
@ -140,6 +140,13 @@ pub async fn database_works<'a, T: MCDatabase>(
|
|||||||
// get captcha cooldown duration
|
// get captcha cooldown duration
|
||||||
assert_eq!(db.get_captcha_cooldown(c.key).await.unwrap(), c.duration);
|
assert_eq!(db.get_captcha_cooldown(c.key).await.unwrap(), c.duration);
|
||||||
|
|
||||||
|
// add traffic pattern
|
||||||
|
db.add_traffic_pattern(p.username, c.key, tp).await.unwrap();
|
||||||
|
assert_eq!(
|
||||||
|
&db.get_traffic_pattern(p.username, c.key).await.unwrap(),
|
||||||
|
tp
|
||||||
|
);
|
||||||
|
|
||||||
// add captcha levels
|
// add captcha levels
|
||||||
db.add_captcha_levels(p.username, c.key, l).await.unwrap();
|
db.add_captcha_levels(p.username, c.key, l).await.unwrap();
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user