summaryrefslogtreecommitdiffstats
path: root/server/src/routes/federation.rs
blob: 019a9a71b90dd6b30a09e75bd92532cf6eeb6521 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
use crate::api::community::ListCommunities;
use crate::api::Perform;
use crate::api::{Oper, UserOperation};
use crate::apub;
use crate::settings::Settings;
use actix_web::web::Query;
use actix_web::{web, HttpResponse};

pub fn config(cfg: &mut web::ServiceConfig) {
  if Settings::get().federation_enabled {
    println!("federation enabled, host is {}", Settings::get().hostname);
    cfg
      .route(
        "/federation/c/{community_name}",
        web::get().to(apub::community::get_apub_community),
      )
      .route(
        "/federation/c/{community_name}/followers",
        web::get().to(apub::community::get_apub_community_followers),
      )
      .route(
        "/federation/u/{user_name}",
        web::get().to(apub::user::get_apub_user),
      )
      // TODO: this is a very quick and dirty implementation for http api calls
      .route(
        "/api/v1/communities/list",
        web::get().to(|query: Query<ListCommunities>| {
          let res = Oper::new(UserOperation::ListCommunities, query.into_inner())
            .perform()
            .unwrap();
          HttpResponse::Ok()
            .content_type("application/json")
            .body(serde_json::to_string(&res).unwrap())
        }),
      );
  }
}