survey/src/api/v1/mcaptcha/mod.rs

58 lines
1.8 KiB
Rust

/*
* Copyright (C) 2023 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 actix_web::web::ServiceConfig;
pub mod db;
pub mod hooks;
pub fn services(cfg: &mut ServiceConfig) {
hooks::services(cfg);
}
pub mod routes {
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
pub struct Mcaptcha {
pub upload: &'static str,
pub download: &'static str,
pub register: &'static str,
}
impl Mcaptcha {
pub const fn new() -> Self {
Self {
register: "/mcaptcha/api/v1/register",
upload: "/mcaptcha/api/v1/{campaign_id}/upload",
download: "/mcapthca/api/v1/{campaign_id}/download",
}
}
pub fn get_download_route(&self, campaign_id: &str, page: usize) -> String {
format!(
"{}?page={}",
self.download.replace("{campaign_id}", campaign_id),
page
)
}
pub fn get_upload_route(&self, campaign_id: &str) -> String {
self.upload.replace("{campaign_id}", campaign_id)
}
}
}