lemmy/server/src/apub/mod.rs

50 lines
897 B
Rust
Raw Normal View History

pub mod community;
pub mod post;
pub mod puller;
pub mod user;
use crate::Settings;
2020-03-16 11:30:25 -06:00
use actix_web::body::Body;
use actix_web::HttpResponse;
use url::Url;
2020-03-18 19:16:17 -06:00
fn create_apub_response<T>(json: &T) -> HttpResponse<Body>
where
T: serde::ser::Serialize,
{
2020-03-16 11:30:25 -06:00
HttpResponse::Ok()
.content_type("application/activity+json")
2020-03-18 19:16:17 -06:00
.json(json)
}
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",
};
Url::parse(&format!(
2020-02-29 10:38:47 -07:00
"{}://{}/federation/{}/{}",
get_apub_protocol_string(),
Settings::get().hostname,
point,
name
))
.unwrap()
}
2020-02-29 10:38:47 -07:00
pub fn get_apub_protocol_string() -> &'static str {
2020-03-18 15:09:00 -06:00
if Settings::get().federation.tls_enabled {
"https"
} else {
"http"
}
2020-02-29 10:38:47 -07:00
}