Radish alpha
r
Radicle web interface
Radicle
Git (anonymous pull)
Log in to clone via SSH
httpd: Add endpoint with tracking information
Sebastian Martinez committed 2 years ago
commit 80c1bb5b221df5b29db5f4630b81e011858d6fed
parent c197bc8763b226adc82cc6494ca9716c4ad64992
1 file changed +19 -1
modified radicle-httpd/src/api/v1/node.rs
@@ -4,7 +4,7 @@ use axum::routing::get;
use axum::{Json, Router};
use serde_json::json;

-
use radicle::node::Handle;
+
use radicle::node::{tracking, Handle};
use radicle::Node;

use crate::api::error::Error;
@@ -13,6 +13,7 @@ use crate::api::Context;
pub fn router(ctx: Context) -> Router {
    Router::new()
        .route("/node", get(node_handler))
+
        .route("/node/tracking/repos", get(node_tracking_repos_handler))
        .with_state(ctx)
}

@@ -41,3 +42,20 @@ async fn node_handler(State(ctx): State<Context>) -> impl IntoResponse {

    Ok::<_, Error>(Json(response))
}
+

+
/// Return local tracking repos information.
+
/// `GET /node/tracking/repos`
+
async fn node_tracking_repos_handler(State(ctx): State<Context>) -> impl IntoResponse {
+
    let tracking = ctx.profile.tracking()?;
+
    let mut repos = Vec::new();
+

+
    for tracking::Repo { id, scope, policy } in tracking.repo_policies()? {
+
        repos.push(json!({
+
            "id": id,
+
            "scope": scope,
+
            "policy": policy,
+
        }));
+
    }
+

+
    Ok::<_, Error>(Json(repos))
+
}