#
mcaptcha/api/v1/mcaptcha/
mod.rs

    1// Copyright (C) 2022  Aravinth Manivannan <realaravinth@batsense.net>
    2// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
    3//
    4// SPDX-License-Identifier: AGPL-3.0-or-later
    5
    6pub mod create;
    7pub mod delete;
    8pub mod easy;
    9pub mod get;
    10pub mod stats;
    11#[cfg(test)]
    12pub mod test;
    13pub mod update;
    14
    15pub fn get_random(len: usize) -> String {
    16    use std::iter;
    17
    18    use rand::{distributions::Alphanumeric, rngs::ThreadRng, thread_rng, Rng};
    19
    20    let mut rng: ThreadRng = thread_rng();
    21
    22    iter::repeat(())
    23        .map(|()| rng.sample(Alphanumeric))
    24        .map(char::from)
    25        .take(len)
    26        .collect::<String>()
    27}
    28
    29pub fn services(cfg: &mut actix_web::web::ServiceConfig) {
    30    easy::services(cfg);
    31    cfg.service(stats::get);
    32    cfg.service(create::create);
    33    cfg.service(get::get_captcha);
    34    cfg.service(update::update_key);
    35    cfg.service(update::update_captcha);
    36    cfg.service(delete::delete);
    37}
    38
    39pub mod routes {
    40    use super::easy::routes::Easy;
    41    use super::stats::routes::Stats;
    42
    43    pub struct Captcha {
    44        pub create: &'static str,
    45        pub update: &'static str,
    46        pub get: &'static str,
    47        pub delete: &'static str,
    48        pub update_key: &'static str,
    49        pub easy: Easy,
    50        pub stats: Stats,
    51    }
    52
    53    impl Captcha {
    54        pub const fn new() -> Self {
    55            Self {
    56                create: "/api/v1/mcaptcha/create",
    57                update: "/api/v1/mcaptcha/update",
    58                get: "/api/v1/mcaptcha/get",
    59                update_key: "/api/v1/mcaptcha/update/key",
    60                delete: "/api/v1/mcaptcha/delete",
    61                easy: Easy::new(),
    62                stats: Stats::new(),
    63            }
    64        }
    65    }
    66}