2020-07-10 18:15:41 +00:00
|
|
|
#[macro_use]
|
2020-12-21 23:27:42 +00:00
|
|
|
extern crate strum_macros;
|
2021-08-04 21:13:51 +00:00
|
|
|
#[macro_use]
|
|
|
|
extern crate smart_default;
|
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-07-10 18:15:41 +00:00
|
|
|
pub mod settings;
|
2021-03-01 17:24:11 +00:00
|
|
|
|
2021-09-20 15:46:34 +00:00
|
|
|
pub mod claims;
|
2022-06-02 14:33:41 +00:00
|
|
|
pub mod error;
|
2022-05-03 17:44:13 +00:00
|
|
|
pub mod request;
|
2020-09-14 15:29:50 +00:00
|
|
|
pub mod utils;
|
2021-02-09 18:26:06 +00:00
|
|
|
pub mod version;
|
2020-07-10 18:15:41 +00:00
|
|
|
|
2022-11-26 20:34:38 +00:00
|
|
|
use serde::{Deserialize, Serialize};
|
2023-02-22 02:25:26 +00:00
|
|
|
use std::{collections::HashMap, fmt, time::Duration};
|
2022-11-26 20:34:38 +00:00
|
|
|
use url::Url;
|
2020-09-01 14:25:34 +00:00
|
|
|
|
|
|
|
pub type ConnectionId = usize;
|
2021-03-18 20:25:21 +00:00
|
|
|
|
2022-03-24 16:33:23 +00:00
|
|
|
pub const REQWEST_TIMEOUT: Duration = Duration::from_secs(10);
|
|
|
|
|
2021-03-18 20:25:21 +00:00
|
|
|
#[derive(PartialEq, Eq, Hash, Debug, Clone)]
|
|
|
|
pub struct IpAddr(pub String);
|
|
|
|
|
|
|
|
impl fmt::Display for IpAddr {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
write!(f, "{}", self.0)
|
|
|
|
}
|
|
|
|
}
|
2020-07-10 18:15:41 +00:00
|
|
|
|
2022-11-26 20:34:38 +00:00
|
|
|
#[derive(Serialize, Deserialize, Debug)]
|
|
|
|
pub struct WebfingerLink {
|
|
|
|
pub rel: Option<String>,
|
|
|
|
#[serde(rename = "type")]
|
|
|
|
pub kind: Option<String>,
|
|
|
|
pub href: Option<Url>,
|
2023-02-23 14:51:33 +00:00
|
|
|
#[serde(default)]
|
2023-02-22 02:25:26 +00:00
|
|
|
pub properties: HashMap<String, String>,
|
2022-11-26 20:34:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize, Debug)]
|
|
|
|
pub struct WebfingerResponse {
|
|
|
|
pub subject: String,
|
|
|
|
pub links: Vec<WebfingerLink>,
|
|
|
|
}
|
|
|
|
|
2020-08-11 14:31:05 +00:00
|
|
|
#[macro_export]
|
|
|
|
macro_rules! location_info {
|
|
|
|
() => {
|
|
|
|
format!(
|
|
|
|
"None value at {}:{}, column {}",
|
|
|
|
file!(),
|
|
|
|
line!(),
|
|
|
|
column!()
|
|
|
|
)
|
|
|
|
};
|
|
|
|
}
|
2023-02-23 14:51:33 +00:00
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
|
|
|
use reqwest::Client;
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
#[ignore]
|
|
|
|
async fn test_webfinger() {
|
|
|
|
let client = Client::default();
|
|
|
|
let fetch_url =
|
|
|
|
"https://kino.schuerz.at/.well-known/webfinger?resource=acct:h0e@kino.schuerz.at";
|
|
|
|
|
|
|
|
let response = client.get(fetch_url).send().await.unwrap();
|
|
|
|
|
|
|
|
let res = response.json::<WebfingerResponse>().await;
|
|
|
|
assert!(res.is_ok());
|
|
|
|
}
|
|
|
|
}
|