feat & fix: ip queues
This commit is contained in:
parent
ce1b3b0856
commit
c377cf431e
2 changed files with 16 additions and 3 deletions
|
@ -16,6 +16,7 @@
|
|||
*/
|
||||
//! PoW Verification module
|
||||
|
||||
use actix_web::HttpRequest;
|
||||
use actix_web::{web, HttpResponse, Responder};
|
||||
use libmcaptcha::pow::Work;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
@ -37,11 +38,13 @@ pub struct ValidationToken {
|
|||
/// if verification is successful
|
||||
#[my_codegen::post(path = "V1_API_ROUTES.pow.verify_pow()")]
|
||||
pub async fn verify_pow(
|
||||
req: HttpRequest,
|
||||
payload: web::Json<Work>,
|
||||
data: AppData,
|
||||
) -> ServiceResult<impl Responder> {
|
||||
let ip = req.connection_info().peer_addr().unwrap().to_string();
|
||||
let key = payload.key.clone();
|
||||
let res = data.captcha.verify_pow(payload.into_inner()).await?;
|
||||
let res = data.captcha.verify_pow(payload.into_inner(), ip).await?;
|
||||
data.stats.record_solve(&data, &key).await?;
|
||||
let payload = ValidationToken { token: res };
|
||||
Ok(HttpResponse::Ok().json(payload))
|
||||
|
|
14
src/data.rs
14
src/data.rs
|
@ -83,7 +83,12 @@ impl SystemGroup {
|
|||
enum_system_wrapper!(get_pow, String, CaptchaResult<Option<PoWConfig>>);
|
||||
|
||||
// utility function to verify [Work]
|
||||
enum_system_wrapper!(verify_pow, Work, CaptchaResult<String>);
|
||||
pub async fn verify_pow(&self, msg: Work, ip: String) -> CaptchaResult<String> {
|
||||
match self {
|
||||
Self::Embedded(val) => val.verify_pow(msg, ip).await,
|
||||
Self::Redis(val) => val.verify_pow(msg, ip).await,
|
||||
}
|
||||
}
|
||||
|
||||
// utility function to validate verification tokens
|
||||
enum_system_wrapper!(
|
||||
|
@ -111,7 +116,12 @@ impl SystemGroup {
|
|||
.build()
|
||||
.unwrap();
|
||||
|
||||
SystemBuilder::default().pow(pow).cache(c).master(m).build()
|
||||
SystemBuilder::default()
|
||||
.pow(pow)
|
||||
.cache(c)
|
||||
.master(m)
|
||||
.runners(num_cpus::get_physical())
|
||||
.build()
|
||||
}
|
||||
|
||||
// read settings, if Redis is configured then produce a Redis mCaptcha cache
|
||||
|
|
Loading…
Reference in a new issue