mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2026-02-11 10:05:41 +00:00
pow stats
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
pub mod duration;
|
||||
pub mod levels;
|
||||
pub mod mcaptcha;
|
||||
pub mod stats;
|
||||
|
||||
pub use super::auth::is_authenticated;
|
||||
|
||||
|
||||
28
src/api/v1/mcaptcha/stats.rs
Normal file
28
src/api/v1/mcaptcha/stats.rs
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright (C) 2021 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
use sqlx::PgPool;
|
||||
|
||||
pub async fn fetched(key: &str, db: &PgPool) {
|
||||
let _ = sqlx::query!(
|
||||
"INSERT INTO mcaptcha_pow_fetched_stats
|
||||
(config_id) VALUES ((SELECT config_id FROM mcaptcha_config WHERE key = $1))",
|
||||
&key,
|
||||
)
|
||||
.execute(db)
|
||||
.await;
|
||||
}
|
||||
@@ -22,6 +22,7 @@ use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::GetDurationResp;
|
||||
use super::I32Levels;
|
||||
use crate::api::v1::mcaptcha::stats::fetched;
|
||||
use crate::errors::*;
|
||||
use crate::Data;
|
||||
|
||||
@@ -64,9 +65,12 @@ pub async fn get_config(
|
||||
init_mcaptcha(&data, &payload.key).await?;
|
||||
let config = data
|
||||
.captcha
|
||||
.get_pow(payload.key)
|
||||
.get_pow(payload.key.clone())
|
||||
.await
|
||||
.expect("mcaptcha should be initialized and ready to go");
|
||||
// background it. would require data::Data to be static
|
||||
// to satidfy lifetime
|
||||
fetched(&payload.key, &data.db).await;
|
||||
Ok(HttpResponse::Ok().json(config))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user