2 extern crate lazy_static;
12 use crate::settings::Settings;
16 pub type ConnectionId = usize;
17 pub type PostId = i32;
18 pub type CommunityId = i32;
19 pub type UserId = i32;
20 pub type IPAddr = String;
23 macro_rules! location_info {
26 "None value at {}:{}, column {}",
34 #[derive(Debug, Error)]
35 #[error("{{\"error\":\"{message}\"}}")]
41 pub fn err(msg: &str) -> Self {
43 message: msg.to_string(),
49 pub struct LemmyError {
50 pub inner: anyhow::Error,
53 impl<T> From<T> for LemmyError
55 T: Into<anyhow::Error>,
57 fn from(t: T) -> Self {
58 LemmyError { inner: t.into() }
62 impl std::fmt::Display for LemmyError {
63 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
68 impl actix_web::error::ResponseError for LemmyError {}
71 pub static ref WEBFINGER_COMMUNITY_REGEX: Regex = Regex::new(&format!(
72 "^group:([a-z0-9_]{{3, 20}})@{}$",
73 Settings::get().hostname
76 pub static ref WEBFINGER_USER_REGEX: Regex = Regex::new(&format!(
77 "^acct:([a-z0-9_]{{3, 20}})@{}$",
78 Settings::get().hostname
81 pub static ref CACHE_CONTROL_REGEX: Regex =
82 Regex::new("^((text|image)/.+|application/javascript)$").unwrap();