2020-01-02 18:22:23 +00:00
|
|
|
use crate::api::community::ListCommunities;
|
2020-02-05 17:51:03 +00:00
|
|
|
use crate::api::Oper;
|
2020-01-02 18:22:23 +00:00
|
|
|
use crate::api::Perform;
|
2019-12-31 12:55:33 +00:00
|
|
|
use crate::apub;
|
2020-01-02 18:22:23 +00:00
|
|
|
use crate::settings::Settings;
|
|
|
|
use actix_web::web::Query;
|
|
|
|
use actix_web::{web, HttpResponse};
|
2020-01-14 15:26:19 +00:00
|
|
|
use diesel::r2d2::{ConnectionManager, Pool};
|
|
|
|
use diesel::PgConnection;
|
2019-12-31 12:55:33 +00:00
|
|
|
|
|
|
|
pub fn config(cfg: &mut web::ServiceConfig) {
|
2020-03-18 21:09:00 +00:00
|
|
|
if Settings::get().federation.enabled {
|
2020-01-02 18:22:23 +00:00
|
|
|
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),
|
|
|
|
)
|
2020-03-14 00:05:42 +00:00
|
|
|
.route(
|
|
|
|
"/federation/c/{community_name}/outbox",
|
|
|
|
web::get().to(apub::community::get_apub_community_outbox),
|
|
|
|
)
|
2020-01-02 18:22:23 +00:00
|
|
|
.route(
|
|
|
|
"/federation/u/{user_name}",
|
|
|
|
web::get().to(apub::user::get_apub_user),
|
|
|
|
)
|
2020-03-16 18:19:04 +00:00
|
|
|
.route(
|
|
|
|
"/federation/p/{post_id}",
|
|
|
|
web::get().to(apub::user::get_apub_user),
|
|
|
|
)
|
2020-03-14 21:03:05 +00:00
|
|
|
// TODO: we should be able to remove this but somehow that breaks the remote community list
|
2020-01-02 18:22:23 +00:00
|
|
|
.route(
|
|
|
|
"/api/v1/communities/list",
|
2020-01-14 15:26:19 +00:00
|
|
|
web::get().to(
|
|
|
|
|query: Query<ListCommunities>, db: web::Data<Pool<ConnectionManager<PgConnection>>>| {
|
2020-02-05 17:51:03 +00:00
|
|
|
let res = Oper::new(query.into_inner())
|
2020-01-14 15:26:19 +00:00
|
|
|
.perform(&db.get().unwrap())
|
|
|
|
.unwrap();
|
|
|
|
HttpResponse::Ok()
|
|
|
|
.content_type("application/json")
|
|
|
|
.body(serde_json::to_string(&res).unwrap())
|
|
|
|
},
|
|
|
|
),
|
2020-01-02 18:22:23 +00:00
|
|
|
);
|
|
|
|
}
|
2019-12-31 12:55:33 +00:00
|
|
|
}
|