2019-12-19 21:59:13 +00:00
|
|
|
pub mod community;
|
|
|
|
pub mod post;
|
2019-12-27 17:25:07 +00:00
|
|
|
pub mod puller;
|
2019-12-19 21:59:13 +00:00
|
|
|
pub mod user;
|
|
|
|
use crate::Settings;
|
|
|
|
|
2020-03-16 17:30:25 +00:00
|
|
|
use actix_web::body::Body;
|
|
|
|
use actix_web::HttpResponse;
|
2020-03-12 00:01:25 +00:00
|
|
|
use url::Url;
|
2019-12-19 21:59:13 +00:00
|
|
|
|
2020-03-19 01:16:17 +00:00
|
|
|
fn create_apub_response<T>(json: &T) -> HttpResponse<Body>
|
|
|
|
where
|
|
|
|
T: serde::ser::Serialize,
|
|
|
|
{
|
2020-03-16 17:30:25 +00:00
|
|
|
HttpResponse::Ok()
|
|
|
|
.content_type("application/activity+json")
|
2020-03-19 01:16:17 +00:00
|
|
|
.json(json)
|
2019-12-19 21:59:13 +00:00
|
|
|
}
|
|
|
|
|
2020-03-16 18:19:04 +00:00
|
|
|
enum EndpointType {
|
|
|
|
Community,
|
|
|
|
User,
|
|
|
|
Post,
|
|
|
|
}
|
|
|
|
|
|
|
|
fn make_apub_endpoint(endpoint_type: EndpointType, name: &str) -> Url {
|
|
|
|
let point = match endpoint_type {
|
|
|
|
EndpointType::Community => "c",
|
|
|
|
EndpointType::User => "u",
|
|
|
|
EndpointType::Post => "p",
|
|
|
|
};
|
|
|
|
|
2020-03-12 00:01:25 +00:00
|
|
|
Url::parse(&format!(
|
2020-02-29 17:38:47 +00:00
|
|
|
"{}://{}/federation/{}/{}",
|
|
|
|
get_apub_protocol_string(),
|
2019-12-19 21:59:13 +00:00
|
|
|
Settings::get().hostname,
|
|
|
|
point,
|
2020-03-16 18:19:04 +00:00
|
|
|
name
|
2020-03-12 00:01:25 +00:00
|
|
|
))
|
|
|
|
.unwrap()
|
2019-12-19 21:59:13 +00:00
|
|
|
}
|
2020-02-29 17:38:47 +00:00
|
|
|
|
2020-03-18 15:08:08 +00:00
|
|
|
pub fn get_apub_protocol_string() -> &'static str {
|
2020-03-18 21:09:00 +00:00
|
|
|
if Settings::get().federation.tls_enabled {
|
|
|
|
"https"
|
|
|
|
} else {
|
|
|
|
"http"
|
|
|
|
}
|
2020-02-29 17:38:47 +00:00
|
|
|
}
|