mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2026-02-12 02:25:41 +00:00
captcha stats
This commit is contained in:
@@ -44,7 +44,10 @@ pub struct UpdateDuration {
|
||||
pub duration: i32,
|
||||
}
|
||||
|
||||
#[my_codegen::post(path="crate::V1_API_ROUTES.duration.update", wrap="crate::CheckLogin")]
|
||||
#[my_codegen::post(
|
||||
path = "crate::V1_API_ROUTES.duration.update",
|
||||
wrap = "crate::CheckLogin"
|
||||
)]
|
||||
async fn update_duration(
|
||||
payload: web::Json<UpdateDuration>,
|
||||
data: web::Data<Data>,
|
||||
@@ -82,7 +85,10 @@ pub struct GetDuration {
|
||||
pub token: String,
|
||||
}
|
||||
|
||||
#[my_codegen::post(path="crate::V1_API_ROUTES.duration.get", wrap="crate::CheckLogin")]
|
||||
#[my_codegen::post(
|
||||
path = "crate::V1_API_ROUTES.duration.get",
|
||||
wrap = "crate::CheckLogin"
|
||||
)]
|
||||
async fn get_duration(
|
||||
payload: web::Json<MCaptchaDetails>,
|
||||
data: web::Data<Data>,
|
||||
@@ -105,21 +111,21 @@ async fn get_duration(
|
||||
pub fn services(cfg: &mut web::ServiceConfig) {
|
||||
cfg.service(get_duration);
|
||||
cfg.service(update_duration);
|
||||
// use crate::define_resource;
|
||||
// use crate::V1_API_ROUTES;
|
||||
//
|
||||
// define_resource!(
|
||||
// cfg,
|
||||
// V1_API_ROUTES.duration.get,
|
||||
// Methods::ProtectPost,
|
||||
// get_duration
|
||||
// );
|
||||
// define_resource!(
|
||||
// cfg,
|
||||
// V1_API_ROUTES.duration.update,
|
||||
// Methods::ProtectPost,
|
||||
// update_duration
|
||||
// );
|
||||
// use crate::define_resource;
|
||||
// use crate::V1_API_ROUTES;
|
||||
//
|
||||
// define_resource!(
|
||||
// cfg,
|
||||
// V1_API_ROUTES.duration.get,
|
||||
// Methods::ProtectPost,
|
||||
// get_duration
|
||||
// );
|
||||
// define_resource!(
|
||||
// cfg,
|
||||
// V1_API_ROUTES.duration.update,
|
||||
// Methods::ProtectPost,
|
||||
// update_duration
|
||||
// );
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -67,7 +67,7 @@ pub fn services(cfg: &mut web::ServiceConfig) {
|
||||
|
||||
// TODO redo mcaptcha table to include levels as json field
|
||||
// so that the whole thing can be added/udpaed in a single stroke
|
||||
#[my_codegen::post(path="crate::V1_API_ROUTES.levels.add", wrap="crate::CheckLogin")]
|
||||
#[my_codegen::post(path = "crate::V1_API_ROUTES.levels.add", wrap = "crate::CheckLogin")]
|
||||
async fn add_levels(
|
||||
payload: web::Json<AddLevels>,
|
||||
data: web::Data<Data>,
|
||||
@@ -120,7 +120,10 @@ pub struct UpdateLevels {
|
||||
pub key: String,
|
||||
}
|
||||
|
||||
#[my_codegen::post(path="crate::V1_API_ROUTES.levels.update", wrap="crate::CheckLogin")]
|
||||
#[my_codegen::post(
|
||||
path = "crate::V1_API_ROUTES.levels.update",
|
||||
wrap = "crate::CheckLogin"
|
||||
)]
|
||||
async fn update_levels(
|
||||
payload: web::Json<UpdateLevels>,
|
||||
data: web::Data<Data>,
|
||||
@@ -178,7 +181,10 @@ async fn update_levels(
|
||||
Ok(HttpResponse::Ok())
|
||||
}
|
||||
|
||||
#[my_codegen::post(path="crate::V1_API_ROUTES.levels.delete", wrap="crate::CheckLogin")]
|
||||
#[my_codegen::post(
|
||||
path = "crate::V1_API_ROUTES.levels.delete",
|
||||
wrap = "crate::CheckLogin"
|
||||
)]
|
||||
async fn delete_levels(
|
||||
payload: web::Json<UpdateLevels>,
|
||||
data: web::Data<Data>,
|
||||
@@ -205,7 +211,7 @@ async fn delete_levels(
|
||||
Ok(HttpResponse::Ok())
|
||||
}
|
||||
|
||||
#[my_codegen::post(path="crate::V1_API_ROUTES.levels.get", wrap="crate::CheckLogin")]
|
||||
#[my_codegen::post(path = "crate::V1_API_ROUTES.levels.get", wrap = "crate::CheckLogin")]
|
||||
async fn get_levels(
|
||||
payload: web::Json<MCaptchaDetails>,
|
||||
data: web::Data<Data>,
|
||||
|
||||
@@ -111,7 +111,10 @@ pub async fn add_mcaptcha_util(
|
||||
Ok(resp)
|
||||
}
|
||||
|
||||
#[my_codegen::post(path="crate::V1_API_ROUTES.mcaptcha.update_key", wrap="crate::CheckLogin")]
|
||||
#[my_codegen::post(
|
||||
path = "crate::V1_API_ROUTES.mcaptcha.update_key",
|
||||
wrap = "crate::CheckLogin"
|
||||
)]
|
||||
async fn update_token(
|
||||
payload: web::Json<MCaptchaDetails>,
|
||||
data: web::Data<Data>,
|
||||
@@ -162,7 +165,10 @@ async fn update_token_helper(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[my_codegen::post(path="crate::V1_API_ROUTES.mcaptcha.get_token", wrap="crate::CheckLogin")]
|
||||
#[my_codegen::post(
|
||||
path = "crate::V1_API_ROUTES.mcaptcha.get_token",
|
||||
wrap = "crate::CheckLogin"
|
||||
)]
|
||||
async fn get_token(
|
||||
payload: web::Json<MCaptchaDetails>,
|
||||
data: web::Data<Data>,
|
||||
@@ -190,7 +196,10 @@ async fn get_token(
|
||||
Ok(HttpResponse::Ok().json(res))
|
||||
}
|
||||
|
||||
#[my_codegen::post(path="crate::V1_API_ROUTES.mcaptcha.delete", wrap="crate::CheckLogin")]
|
||||
#[my_codegen::post(
|
||||
path = "crate::V1_API_ROUTES.mcaptcha.delete",
|
||||
wrap = "crate::CheckLogin"
|
||||
)]
|
||||
async fn delete_mcaptcha(
|
||||
payload: web::Json<MCaptchaDetails>,
|
||||
data: web::Data<Data>,
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
pub mod duration;
|
||||
pub mod levels;
|
||||
pub mod mcaptcha;
|
||||
pub mod stats;
|
||||
|
||||
pub fn get_random(len: usize) -> String {
|
||||
use std::iter;
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
/// record PoWConfig fetches
|
||||
#[inline]
|
||||
pub async fn record_fetch(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;
|
||||
}
|
||||
|
||||
/// record PoWConfig solves
|
||||
#[inline]
|
||||
pub async fn record_solve(key: &str, db: &PgPool) {
|
||||
let _ = sqlx::query!(
|
||||
"INSERT INTO mcaptcha_pow_solved_stats
|
||||
(config_id) VALUES ((SELECT config_id FROM mcaptcha_config WHERE key = $1))",
|
||||
&key,
|
||||
)
|
||||
.execute(db)
|
||||
.await;
|
||||
}
|
||||
|
||||
/// record PoWConfig confirms
|
||||
#[inline]
|
||||
pub async fn record_confirm(key: &str, db: &PgPool) {
|
||||
let _ = sqlx::query!(
|
||||
"INSERT INTO mcaptcha_pow_confirmed_stats
|
||||
(config_id) VALUES ((SELECT config_id FROM mcaptcha_config WHERE key = $1))",
|
||||
&key,
|
||||
)
|
||||
.execute(db)
|
||||
.await;
|
||||
}
|
||||
Reference in New Issue
Block a user