mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2025-02-17 08:59:46 +03:00
feat: def interface to get traffic pattern
This commit is contained in:
parent
a6920f5f36
commit
212c03a0e2
3 changed files with 18 additions and 1 deletions
|
@ -44,6 +44,9 @@ pub enum DBError {
|
|||
/// Captcha not found
|
||||
#[error("Captcha not found")]
|
||||
CaptchaNotFound,
|
||||
/// Traffic pattern not found
|
||||
#[error("Traffic pattern not found")]
|
||||
TrafficPatternNotFound,
|
||||
}
|
||||
|
||||
/// 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,
|
||||
pattern: &TrafficPattern,
|
||||
) -> 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
|
||||
pub struct TrafficPattern {
|
||||
/// average traffic of user's website
|
||||
|
|
|
@ -140,6 +140,13 @@ pub async fn database_works<'a, T: MCDatabase>(
|
|||
// get captcha cooldown 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
|
||||
db.add_captcha_levels(p.username, c.key, l).await.unwrap();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue