mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2026-02-11 10:05:41 +00:00
feat: add database method to get all easy captcha configurations with pagination
This commit is contained in:
@@ -202,6 +202,13 @@ pub trait MCDatabase: std::marker::Send + std::marker::Sync + CloneSPDatabase {
|
||||
captcha_key: &str,
|
||||
) -> DBResult<TrafficPattern>;
|
||||
|
||||
/// Get all easy captcha configurations on instance
|
||||
async fn get_all_easy_captchas(
|
||||
&self,
|
||||
limit: usize,
|
||||
offset: usize,
|
||||
) -> DBResult<Vec<EasyCaptcha>>;
|
||||
|
||||
/// Delete traffic configuration
|
||||
async fn delete_traffic_pattern(
|
||||
&self,
|
||||
@@ -383,6 +390,15 @@ pub struct AddNotification<'a> {
|
||||
pub message: &'a str,
|
||||
}
|
||||
|
||||
#[derive(Default, PartialEq, Serialize, Deserialize, Clone, Debug)]
|
||||
/// Represents Easy captcha configuration
|
||||
pub struct EasyCaptcha {
|
||||
/// traffic pattern of easy captcha
|
||||
pub traffic_pattern: TrafficPattern,
|
||||
/// captcha key/sitekey
|
||||
pub key: String,
|
||||
}
|
||||
|
||||
#[derive(Default, PartialEq, Serialize, Deserialize, Clone, Debug)]
|
||||
/// User's traffic pattern; used in generating a captcha configuration
|
||||
pub struct TrafficPattern {
|
||||
|
||||
@@ -223,6 +223,11 @@ pub async fn database_works<'a, T: MCDatabase>(
|
||||
tp
|
||||
);
|
||||
|
||||
// get all traffic patterns
|
||||
let patterns = db.get_all_easy_captchas(10, 0).await.unwrap();
|
||||
assert_eq!(patterns.get(0).as_ref().unwrap().key, c.key);
|
||||
assert_eq!(&patterns.get(0).unwrap().traffic_pattern, tp);
|
||||
|
||||
// delete traffic pattern
|
||||
db.delete_traffic_pattern(p.username, c.key).await.unwrap();
|
||||
assert!(
|
||||
|
||||
Reference in New Issue
Block a user