X-Git-Url: http://these/git/?a=blobdiff_plain;f=server%2Fsrc%2Froutes%2Ffederation.rs;fp=server%2Fsrc%2Froutes%2Ffederation.rs;h=6816f1bc036f622db5a0d603db5b371dbbf4c542;hb=d932acad165f21f0cc7c952805596a60fc068627;hp=ea6039d6bd34722d0cb306babe41fd3508562fbc;hpb=420fb5a847cc549a46596407c32c9ad8d581b321;p=lemmy.git diff --git a/server/src/routes/federation.rs b/server/src/routes/federation.rs index ea6039d6..6816f1bc 100644 --- a/server/src/routes/federation.rs +++ b/server/src/routes/federation.rs @@ -1,18 +1,42 @@ +use crate::api::community::ListCommunities; +use crate::api::Oper; +use crate::api::Perform; use crate::apub; -use actix_web::web; +use crate::settings::Settings; +use actix_web::web::Query; +use actix_web::{web, HttpResponse}; +use diesel::r2d2::{ConnectionManager, Pool}; +use diesel::PgConnection; pub fn config(cfg: &mut web::ServiceConfig) { - 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), - ); + 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, db: web::Data>>| { + let res = Oper::new(query.into_inner()) + .perform(&db.get().unwrap()) + .unwrap(); + HttpResponse::Ok() + .content_type("application/json") + .body(serde_json::to_string(&res).unwrap()) + }, + ), + ); + } }