lemmy/server/src/routes/federation.rs

54 lines
1.7 KiB
Rust

use crate::api::community::ListCommunities;
use crate::api::Oper;
use crate::api::Perform;
use crate::apub;
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) {
if Settings::get().federation.enabled {
println!("federation enabled, host is {}", Settings::get().hostname);
cfg
.route(
"/federation/communities",
web::get().to(apub::community::get_apub_community_list),
)
.route(
"/federation/c/{community_name}",
web::get().to(apub::community::get_apub_community_http),
)
.route(
"/federation/c/{community_name}/followers",
web::get().to(apub::community::get_apub_community_followers),
)
.route(
"/federation/c/{community_name}/outbox",
web::get().to(apub::community::get_apub_community_outbox),
)
.route(
"/federation/u/{user_name}",
web::get().to(apub::user::get_apub_user),
)
.route(
"/federation/p/{post_id}",
web::get().to(apub::user::get_apub_user),
)
// TODO: we should be able to remove this but somehow that breaks the remote community list
.route(
"/api/v1/communities/list",
web::get().to(
|query: Query<ListCommunities>, db: web::Data<Pool<ConnectionManager<PgConnection>>>| {
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())
},
),
);
}
}