add umbrella crate

This commit is contained in:
Aleksandr 2025-09-20 22:55:40 +03:00
parent d171fc723b
commit fe04530f84
17 changed files with 247 additions and 5 deletions

8
captcha/Cargo.toml Normal file
View file

@ -0,0 +1,8 @@
[package]
name = "viendesu-captcha"
version = "0.1.0"
edition = "2024"
[dependencies]
eva.workspace = true
viendesu-core.workspace = true

22
captcha/src/error.rs Normal file
View file

@ -0,0 +1,22 @@
use eva::str::ToCompactString as _;
use viendesu_core::{
errors::{Aux, Generic},
mk_error,
};
pub type CaptchaResult<T> = Result<T, CaptchaError>;
mk_error!(CaptchaError);
impl From<CaptchaError> for Aux {
fn from(value: CaptchaError) -> Self {
Self::Captcha(value.0.to_compact_string())
}
}
impl<S> From<CaptchaError> for Generic<S> {
fn from(value: CaptchaError) -> Self {
Self::Aux(value.into())
}
}

32
captcha/src/lib.rs Normal file
View file

@ -0,0 +1,32 @@
use eva::fut::Fut;
use viendesu_core::{
bail,
types::captcha::Token,
world::{World, WorldMut},
};
use self::error::CaptchaResult;
pub mod error;
pub trait Service: Send + Sync {
fn verify<W: WorldMut>(
&self,
w: World<W>,
token: &Token,
) -> impl Fut<Output = CaptchaResult<()>>;
}
impl Service for bool {
async fn verify<W: WorldMut>(&self, w: World<W>, token: &Token) -> CaptchaResult<()> {
_ = w;
_ = token;
if *self {
Ok(())
} else {
bail!("invalid captcha")
}
}
}