mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2026-02-11 18:15:39 +00:00
feat: advance sitekey edit now allows modifying publication status
This commit is contained in:
@@ -130,6 +130,7 @@ async fn create(
|
||||
levels,
|
||||
duration: data.settings.captcha.default_difficulty_strategy.duration,
|
||||
description: payload.description,
|
||||
publish_benchmarks: payload.publish_benchmarks,
|
||||
};
|
||||
|
||||
let mcaptcha_config = create_runner(&msg, &data, &username).await?;
|
||||
@@ -137,11 +138,6 @@ async fn create(
|
||||
.add_traffic_pattern(&username, &mcaptcha_config.key, &pattern)
|
||||
.await?;
|
||||
|
||||
if payload.publish_benchmarks {
|
||||
data.db
|
||||
.analytics_create_psuedo_id_if_not_exists(&mcaptcha_config.key)
|
||||
.await?;
|
||||
}
|
||||
Ok(HttpResponse::Ok().json(mcaptcha_config))
|
||||
}
|
||||
|
||||
@@ -166,21 +162,12 @@ async fn update(
|
||||
let levels =
|
||||
calculate(&pattern, &data.settings.captcha.default_difficulty_strategy)?;
|
||||
|
||||
if payload.pattern.publish_benchmarks {
|
||||
data.db
|
||||
.analytics_create_psuedo_id_if_not_exists(&payload.key)
|
||||
.await?;
|
||||
} else {
|
||||
data.db
|
||||
.analytics_delete_all_records_for_campaign(&payload.key)
|
||||
.await?;
|
||||
}
|
||||
|
||||
let msg = UpdateCaptcha {
|
||||
levels,
|
||||
duration: data.settings.captcha.default_difficulty_strategy.duration,
|
||||
description: payload.pattern.description,
|
||||
key: payload.key,
|
||||
publish_benchmarks: payload.pattern.publish_benchmarks,
|
||||
};
|
||||
|
||||
update_captcha_runner(&msg, &data, &username).await?;
|
||||
|
||||
@@ -76,6 +76,7 @@ pub struct UpdateCaptcha {
|
||||
pub duration: u32,
|
||||
pub description: String,
|
||||
pub key: String,
|
||||
pub publish_benchmarks: bool,
|
||||
}
|
||||
|
||||
#[my_codegen::post(
|
||||
@@ -139,6 +140,16 @@ pub mod runner {
|
||||
e
|
||||
);
|
||||
}
|
||||
|
||||
if payload.publish_benchmarks {
|
||||
data.db
|
||||
.analytics_create_psuedo_id_if_not_exists(&payload.key)
|
||||
.await?;
|
||||
} else {
|
||||
data.db
|
||||
.analytics_delete_all_records_for_campaign(&payload.key)
|
||||
.await?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,15 +35,22 @@ struct AdvanceEditPage {
|
||||
name: String,
|
||||
key: String,
|
||||
levels: Vec<Level>,
|
||||
publish_benchmarks: bool,
|
||||
}
|
||||
|
||||
impl AdvanceEditPage {
|
||||
fn new(config: Captcha, levels: Vec<Level>, key: String) -> Self {
|
||||
fn new(
|
||||
config: Captcha,
|
||||
levels: Vec<Level>,
|
||||
key: String,
|
||||
publish_benchmarks: bool,
|
||||
) -> Self {
|
||||
AdvanceEditPage {
|
||||
duration: config.duration as u32,
|
||||
name: config.description,
|
||||
levels,
|
||||
key,
|
||||
publish_benchmarks,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -63,8 +70,9 @@ pub async fn advance(
|
||||
|
||||
let config = data.db.get_captcha_config(&username, &key).await?;
|
||||
let levels = data.db.get_captcha_levels(Some(&username), &key).await?;
|
||||
let publish_benchmarks = data.db.analytics_captcha_is_published(&key).await?;
|
||||
|
||||
let body = AdvanceEditPage::new(config, levels, key)
|
||||
let body = AdvanceEditPage::new(config, levels, key, publish_benchmarks)
|
||||
.render_once()
|
||||
.unwrap();
|
||||
Ok(HttpResponse::Ok()
|
||||
@@ -107,12 +115,7 @@ pub async fn easy(
|
||||
Ok(c) => {
|
||||
let config = data.db.get_captcha_config(&username, &key).await?;
|
||||
let publish_benchmarks =
|
||||
match data.db.analytics_get_psuedo_id_from_capmaign_id(&key).await {
|
||||
Ok(_) => Ok(true),
|
||||
Err(db_core::errors::DBError::CaptchaNotFound) => Ok(false),
|
||||
Err(e) => Err(e),
|
||||
}?;
|
||||
println!("publish_benchmarks psot edit: {publish_benchmarks}");
|
||||
data.db.analytics_captcha_is_published(&key).await?;
|
||||
let pattern = TrafficPatternRequest {
|
||||
peak_sustainable_traffic: c.peak_sustainable_traffic as u32,
|
||||
avg_traffic: c.avg_traffic as u32,
|
||||
|
||||
Reference in New Issue
Block a user