feat: def interface to get traffic pattern

This commit is contained in:
realaravinth 2022-05-14 18:45:25 +05:30
parent a6920f5f36
commit 212c03a0e2
No known key found for this signature in database
GPG key ID: AD9F0F08E855ED88
3 changed files with 18 additions and 1 deletions

View file

@ -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

View file

@ -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

View file

@ -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();