2 extern crate lazy_static;
4 extern crate strum_macros;
18 use crate::settings::structs::Settings;
24 pub type ConnectionId = usize;
26 #[derive(PartialEq, Eq, Hash, Debug, Clone)]
27 pub struct IpAddr(pub String);
29 impl fmt::Display for IpAddr {
30 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
31 write!(f, "{}", self.0)
36 macro_rules! location_info {
39 "None value at {}:{}, column {}",
47 #[derive(Debug, Error)]
48 #[error("{{\"error\":\"{message}\"}}")]
54 pub fn err(msg: &str) -> Self {
56 message: msg.to_string(),
62 pub struct LemmyError {
63 pub inner: anyhow::Error,
66 impl<T> From<T> for LemmyError
68 T: Into<anyhow::Error>,
70 fn from(t: T) -> Self {
71 LemmyError { inner: t.into() }
75 impl std::fmt::Display for LemmyError {
76 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
81 impl actix_web::error::ResponseError for LemmyError {
82 fn status_code(&self) -> StatusCode {
83 match self.inner.downcast_ref::<diesel::result::Error>() {
84 Some(diesel::result::Error::NotFound) => StatusCode::NOT_FOUND,
85 _ => StatusCode::INTERNAL_SERVER_ERROR,
91 pub static ref WEBFINGER_COMMUNITY_REGEX: Regex = Regex::new(&format!(
92 "^group:([a-z0-9_]{{3,}})@{}$",
93 Settings::get().hostname()
95 .expect("compile webfinger regex");
96 pub static ref WEBFINGER_USERNAME_REGEX: Regex = Regex::new(&format!(
97 "^acct:([a-z0-9_]{{3,}})@{}$",
98 Settings::get().hostname()
100 .expect("compile webfinger regex");