feat: add `/_conduwuit/local_user_count` endpoint

only enabled if federation is enabled

Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
strawberry 2024-05-23 11:26:27 -04:00 committed by June 🍓🦴
parent 32161801ed
commit 1c7c5bc09c
2 changed files with 16 additions and 1 deletions

View File

@ -155,7 +155,20 @@ pub(crate) async fn syncv3_client_server_json() -> Result<impl IntoResponse> {
/// `/_matrix/federation/v1/version` /// `/_matrix/federation/v1/version`
pub(crate) async fn conduwuit_server_version() -> Result<impl IntoResponse> { pub(crate) async fn conduwuit_server_version() -> Result<impl IntoResponse> {
Ok(Json(serde_json::json!({ Ok(Json(serde_json::json!({
"name": "Conduwuit", "name": "conduwuit",
"version": conduwuit_version(), "version": conduwuit_version(),
}))) })))
} }
/// # `GET /_conduwuit/local_user_count`
///
/// conduwuit-specific API to return the amount of users registered on this
/// homeserver. Endpoint is disabled if federation is disabled for privacy. This
/// only includes active users (not deactivated, no guests, etc)
pub(crate) async fn conduwuit_local_user_count() -> Result<impl IntoResponse> {
let user_count = services().users.list_local_users()?.len();
Ok(Json(serde_json::json!({
"count": user_count
})))
}

View File

@ -220,11 +220,13 @@ pub fn build(router: Router, server: &Server) -> Router {
.ruma_route(server_server::claim_keys_route) .ruma_route(server_server::claim_keys_route)
.ruma_route(server_server::get_hierarchy_route) .ruma_route(server_server::get_hierarchy_route)
.ruma_route(server_server::well_known_server) .ruma_route(server_server::well_known_server)
.route("/_conduwuit/local_user_count", get(client_server::conduwuit_local_user_count))
} else { } else {
router router
.route("/_matrix/federation/*path", any(federation_disabled)) .route("/_matrix/federation/*path", any(federation_disabled))
.route("/.well-known/matrix/server", any(federation_disabled)) .route("/.well-known/matrix/server", any(federation_disabled))
.route("/_matrix/key/*path", any(federation_disabled)) .route("/_matrix/key/*path", any(federation_disabled))
.route("/_conduwuit/local_user_count", any(federation_disabled))
} }
} }