mirror of
https://seed.radicle.dev/rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5.git
synced 2026-11-10 05:30:39 +08:00
@@ -121,6 +121,11 @@ async fn root_handler(Extension(ctx): Extension<Context>) -> impl IntoResponse {
|
||||
"href": "/v1/delegates/:did/projects",
|
||||
"rel": "projects",
|
||||
"type": "GET"
|
||||
},
|
||||
{
|
||||
"href": "/v1/stats",
|
||||
"rel": "stats",
|
||||
"type": "GET"
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
@@ -2,6 +2,7 @@ mod delegates;
|
||||
mod node;
|
||||
mod projects;
|
||||
mod sessions;
|
||||
mod stats;
|
||||
|
||||
use axum::Router;
|
||||
|
||||
@@ -12,7 +13,8 @@ pub fn router(ctx: Context) -> Router {
|
||||
.merge(node::router(ctx.clone()))
|
||||
.merge(sessions::router(ctx.clone()))
|
||||
.merge(delegates::router(ctx.clone()))
|
||||
.merge(projects::router(ctx));
|
||||
.merge(projects::router(ctx.clone()))
|
||||
.merge(stats::router(ctx));
|
||||
|
||||
Router::new().nest("/v1", routes)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
use axum::response::IntoResponse;
|
||||
use axum::routing::get;
|
||||
use axum::{Extension, Json, Router};
|
||||
use serde_json::json;
|
||||
|
||||
use crate::api::error::Error;
|
||||
use crate::api::Context;
|
||||
|
||||
pub fn router(ctx: Context) -> Router {
|
||||
Router::new()
|
||||
.route("/stats", get(stats_handler))
|
||||
.layer(Extension(ctx))
|
||||
}
|
||||
|
||||
/// Return the stats for the node.
|
||||
/// `GET /stats`
|
||||
async fn stats_handler(Extension(ctx): Extension<Context>) -> impl IntoResponse {
|
||||
let storage = &ctx.profile.storage;
|
||||
let projects = storage.projects()?.len();
|
||||
|
||||
Ok::<_, Error>(Json(
|
||||
json!({ "projects": { "count": projects }, "users": { "count": 0 } }),
|
||||
))
|
||||
}
|
||||
Reference in New Issue
Block a user