mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2024-11-27 03:48:52 +03:00
feat: migrate get captcha cooldown period to use db_*
This commit is contained in:
parent
7daffe767c
commit
d061824660
2 changed files with 22 additions and 21 deletions
|
@ -470,6 +470,26 @@
|
|||
},
|
||||
"query": "SELECT name FROM mcaptcha_config \n WHERE key = $1 \n AND user_id = (\n SELECT user_id FROM mcaptcha_users WHERE NAME = $2)"
|
||||
},
|
||||
"ad196ab3ef9dc32f6de2313577ccd6c26eae9ab19df5f71ce182651983efb99a": {
|
||||
"describe": {
|
||||
"columns": [
|
||||
{
|
||||
"name": "duration",
|
||||
"ordinal": 0,
|
||||
"type_info": "Int4"
|
||||
}
|
||||
],
|
||||
"nullable": [
|
||||
false
|
||||
],
|
||||
"parameters": {
|
||||
"Left": [
|
||||
"Text"
|
||||
]
|
||||
}
|
||||
},
|
||||
"query": "SELECT duration FROM mcaptcha_config \n WHERE key = $1"
|
||||
},
|
||||
"ad23588ee4bcbb13e208460ce21e2fa9f1373893934b530b339fea10360b34a8": {
|
||||
"describe": {
|
||||
"columns": [
|
||||
|
|
|
@ -41,13 +41,6 @@ pub async fn get_config(
|
|||
payload: web::Json<GetConfigPayload>,
|
||||
data: AppData,
|
||||
) -> ServiceResult<impl Responder> {
|
||||
// let res = sqlx::query!(
|
||||
// "SELECT EXISTS (SELECT 1 from mcaptcha_config WHERE key = $1)",
|
||||
// &payload.key,
|
||||
// )
|
||||
// .fetch_one(&data.db)
|
||||
// .await?;
|
||||
|
||||
//if res.exists.is_none() {
|
||||
if !data.dblib.captcha_exists(None, &payload.key).await? {
|
||||
return Err(ServiceError::TokenNotFound);
|
||||
|
@ -108,19 +101,7 @@ pub async fn get_config(
|
|||
async fn init_mcaptcha(data: &AppData, key: &str) -> ServiceResult<()> {
|
||||
// get levels
|
||||
let levels = data.dblib.get_captcha_levels(None, key).await?;
|
||||
struct DurationResp {
|
||||
duration: i32,
|
||||
}
|
||||
// get duration
|
||||
let duration = sqlx::query_as!(
|
||||
DurationResp,
|
||||
"SELECT duration FROM mcaptcha_config
|
||||
WHERE key = $1",
|
||||
&key,
|
||||
)
|
||||
.fetch_one(&data.db)
|
||||
.await?;
|
||||
//let (levels, duration) = futures::try_join!(levels_fut, duration_fut).await?;
|
||||
let duration = data.dblib.get_captcha_cooldown(&key).await?;
|
||||
|
||||
// build defense
|
||||
let mut defense = DefenseBuilder::default();
|
||||
|
@ -141,7 +122,7 @@ async fn init_mcaptcha(data: &AppData, key: &str) -> ServiceResult<()> {
|
|||
let mcaptcha = MCaptchaBuilder::default()
|
||||
.defense(defense)
|
||||
// leaky bucket algorithm's emission interval
|
||||
.duration(duration.duration as u64)
|
||||
.duration(duration as u64)
|
||||
// .cache(cache)
|
||||
.build()
|
||||
.unwrap();
|
||||
|
|
Loading…
Reference in a new issue