nekrochan/src/lib.rs

44 řádky
927 B
Rust
Surový Normální zobrazení Historie

2023-12-11 15:18:43 +00:00
use error::NekrochanError;
use lazy_static::lazy_static;
use std::{collections::HashMap, sync::RwLock};
lazy_static! {
pub static ref CAPTCHA: RwLock<HashMap<(String, String, String), String>> =
RwLock::new(HashMap::new());
}
pub mod auth;
pub mod cfg;
pub mod ctx;
pub mod db;
pub mod error;
pub mod files;
pub mod filters;
pub mod markup;
pub mod perms;
pub mod qsform;
pub mod trip;
pub mod web;
pub fn paginate(page_size: i64, count: i64) -> i64 {
count / page_size + (count % page_size).signum()
}
pub fn check_page(
page: i64,
pages: i64,
page_limit: impl Into<Option<i64>>,
) -> Result<(), NekrochanError> {
if page <= 0 || (page > pages && page != 1) {
return Err(NekrochanError::InvalidPageError);
}
if let Some(page_limit) = page_limit.into() {
if page > page_limit {
return Err(NekrochanError::InvalidPageError);
}
}
Ok(())
}