2020-07-10 18:15:41 +00:00
|
|
|
#[macro_use]
|
2020-09-03 19:45:12 +00:00
|
|
|
extern crate lazy_static;
|
2020-12-21 23:27:42 +00:00
|
|
|
#[macro_use]
|
|
|
|
extern crate strum_macros;
|
2020-07-10 18:15:41 +00:00
|
|
|
|
2020-09-14 15:29:50 +00:00
|
|
|
pub mod apub;
|
|
|
|
pub mod email;
|
2020-12-21 23:27:42 +00:00
|
|
|
pub mod rate_limit;
|
2020-09-24 13:53:21 +00:00
|
|
|
pub mod request;
|
2020-07-10 18:15:41 +00:00
|
|
|
pub mod settings;
|
2020-09-14 15:29:50 +00:00
|
|
|
#[cfg(test)]
|
|
|
|
mod test;
|
|
|
|
pub mod utils;
|
2020-07-10 18:15:41 +00:00
|
|
|
|
|
|
|
use crate::settings::Settings;
|
2020-09-14 15:29:50 +00:00
|
|
|
use regex::Regex;
|
2020-09-03 19:45:12 +00:00
|
|
|
use thiserror::Error;
|
2020-09-01 14:25:34 +00:00
|
|
|
|
|
|
|
pub type ConnectionId = usize;
|
|
|
|
pub type PostId = i32;
|
|
|
|
pub type CommunityId = i32;
|
|
|
|
pub type UserId = i32;
|
|
|
|
pub type IPAddr = String;
|
2020-07-10 18:15:41 +00:00
|
|
|
|
2020-08-11 14:31:05 +00:00
|
|
|
#[macro_export]
|
|
|
|
macro_rules! location_info {
|
|
|
|
() => {
|
|
|
|
format!(
|
|
|
|
"None value at {}:{}, column {}",
|
|
|
|
file!(),
|
|
|
|
line!(),
|
|
|
|
column!()
|
|
|
|
)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-09-03 19:45:12 +00:00
|
|
|
#[derive(Debug, Error)]
|
|
|
|
#[error("{{\"error\":\"{message}\"}}")]
|
|
|
|
pub struct APIError {
|
|
|
|
pub message: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl APIError {
|
|
|
|
pub fn err(msg: &str) -> Self {
|
|
|
|
APIError {
|
|
|
|
message: msg.to_string(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-01 14:25:34 +00:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct LemmyError {
|
2020-09-18 14:37:46 +00:00
|
|
|
pub inner: anyhow::Error,
|
2020-09-01 14:25:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<T> From<T> for LemmyError
|
2020-09-02 23:17:35 +00:00
|
|
|
where
|
|
|
|
T: Into<anyhow::Error>,
|
2020-09-01 14:25:34 +00:00
|
|
|
{
|
|
|
|
fn from(t: T) -> Self {
|
|
|
|
LemmyError { inner: t.into() }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl std::fmt::Display for LemmyError {
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
|
|
|
self.inner.fmt(f)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl actix_web::error::ResponseError for LemmyError {}
|
|
|
|
|
2020-07-10 18:15:41 +00:00
|
|
|
lazy_static! {
|
|
|
|
pub static ref WEBFINGER_COMMUNITY_REGEX: Regex = Regex::new(&format!(
|
|
|
|
"^group:([a-z0-9_]{{3, 20}})@{}$",
|
|
|
|
Settings::get().hostname
|
|
|
|
))
|
|
|
|
.unwrap();
|
|
|
|
pub static ref WEBFINGER_USER_REGEX: Regex = Regex::new(&format!(
|
|
|
|
"^acct:([a-z0-9_]{{3, 20}})@{}$",
|
|
|
|
Settings::get().hostname
|
|
|
|
))
|
|
|
|
.unwrap();
|
|
|
|
}
|