]> Untitled Git - lemmy.git/blob - server/src/routes/federation.rs
6816f1bc036f622db5a0d603db5b371dbbf4c542
[lemmy.git] / server / src / routes / federation.rs
1 use crate::api::community::ListCommunities;
2 use crate::api::Oper;
3 use crate::api::Perform;
4 use crate::apub;
5 use crate::settings::Settings;
6 use actix_web::web::Query;
7 use actix_web::{web, HttpResponse};
8 use diesel::r2d2::{ConnectionManager, Pool};
9 use diesel::PgConnection;
10
11 pub fn config(cfg: &mut web::ServiceConfig) {
12   if Settings::get().federation_enabled {
13     println!("federation enabled, host is {}", Settings::get().hostname);
14     cfg
15       .route(
16         "/federation/c/{community_name}",
17         web::get().to(apub::community::get_apub_community),
18       )
19       .route(
20         "/federation/c/{community_name}/followers",
21         web::get().to(apub::community::get_apub_community_followers),
22       )
23       .route(
24         "/federation/u/{user_name}",
25         web::get().to(apub::user::get_apub_user),
26       )
27       // TODO: this is a very quick and dirty implementation for http api calls
28       .route(
29         "/api/v1/communities/list",
30         web::get().to(
31           |query: Query<ListCommunities>, db: web::Data<Pool<ConnectionManager<PgConnection>>>| {
32             let res = Oper::new(query.into_inner())
33               .perform(&db.get().unwrap())
34               .unwrap();
35             HttpResponse::Ok()
36               .content_type("application/json")
37               .body(serde_json::to_string(&res).unwrap())
38           },
39         ),
40       );
41   }
42 }