feat: README, config.example, turnstile integration, exchange rate, auth utils refactor

This commit is contained in:
Ember Moth
2026-07-05 21:15:17 +08:00
parent 25d190b90e
commit 4ffdc89421
19 changed files with 763 additions and 4 deletions
+1
View File
@@ -10,4 +10,5 @@ reqwest = { version = "0.12", features = ["json"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
tokio = { version = "1", features = ["time"] }
tracing = "0.1"
uuid = { version = "1", features = ["v4"] }
+14
View File
@@ -54,6 +54,20 @@ pub async fn verify_with_key(
Ok(resp.success)
}
/// Guard: verify a token and return `Err(TOO_MANY_REQUESTS)` on failure.
///
/// Convenience wrapper used by auth service handlers — avoids repeating the
/// same error mapping in every caller.
pub async fn guard(secret: &str, token: &str, ip: &str) -> anyhow::Result<()> {
let ok = verify(secret, token, ip).await.unwrap_or(false);
if !ok {
// Use a plain anyhow error with a sentinel message; callers in the
// main crate map this to `error_code::TOO_MANY_REQUESTS`.
anyhow::bail!("turnstile_failed");
}
Ok(())
}
/// Generate a random UUID suitable for use as an idempotency key.
pub fn random_uuid() -> String {
uuid::Uuid::new_v4().to_string()