]> Untitled Git - lemmy.git/blob - server/src/apub/mod.rs
Share list of communities over apub, some refactoring
[lemmy.git] / server / src / apub / mod.rs
1 pub mod community;
2 pub mod post;
3 pub mod puller;
4 pub mod user;
5 use crate::Settings;
6
7 use activitystreams::actor::{properties::ApActorProperties, Group};
8 use activitystreams::ext::Ext;
9 use actix_web::body::Body;
10 use actix_web::HttpResponse;
11 use url::Url;
12
13 type GroupExt = Ext<Group, ApActorProperties>;
14
15 fn create_apub_response<T>(json: &T) -> HttpResponse<Body>
16 where
17   T: serde::ser::Serialize,
18 {
19   HttpResponse::Ok()
20     .content_type("application/activity+json")
21     .json(json)
22 }
23
24 enum EndpointType {
25   Community,
26   User,
27   Post,
28 }
29
30 fn make_apub_endpoint(endpoint_type: EndpointType, name: &str) -> Url {
31   let point = match endpoint_type {
32     EndpointType::Community => "c",
33     EndpointType::User => "u",
34     EndpointType::Post => "p",
35   };
36
37   Url::parse(&format!(
38     "{}://{}/federation/{}/{}",
39     get_apub_protocol_string(),
40     Settings::get().hostname,
41     point,
42     name
43   ))
44   .unwrap()
45 }
46
47 pub fn get_apub_protocol_string() -> &'static str {
48   if Settings::get().federation.tls_enabled {
49     "https"
50   } else {
51     "http"
52   }
53 }