mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-24 14:49:58 -07:00
global: snapshot
This commit is contained in:
@@ -1,4 +1,11 @@
|
||||
use axum::{Router, routing::get};
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use axum::{
|
||||
Router,
|
||||
extract::State,
|
||||
response::{IntoResponse, Response},
|
||||
routing::get,
|
||||
};
|
||||
|
||||
use super::AppState;
|
||||
|
||||
@@ -14,5 +21,42 @@ pub trait ApiRoutes {
|
||||
impl ApiRoutes for Router<AppState> {
|
||||
fn add_api_routes(self) -> Self {
|
||||
self.route("/api/query", get(query::handler))
|
||||
.route("/api/vecs/ids", get(vecids_handler))
|
||||
.route("/api/vecs/indexes", get(vecindexes_handler))
|
||||
.route("/api/vecs/id-to-indexes", get(vecid_to_vecindexes_handler))
|
||||
.route("/api/vecs/index-to-ids", get(vecindex_to_vecids_handler))
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn vecids_handler(State(app_state): State<AppState>) -> Response {
|
||||
axum::Json(
|
||||
app_state
|
||||
.query
|
||||
.vec_trees
|
||||
.id_to_index_to_vec
|
||||
.keys()
|
||||
.collect::<Vec<_>>(),
|
||||
)
|
||||
.into_response()
|
||||
}
|
||||
|
||||
pub async fn vecindexes_handler(State(app_state): State<AppState>) -> Response {
|
||||
axum::Json(
|
||||
app_state
|
||||
.query
|
||||
.vec_trees
|
||||
.index_to_id_to_vec
|
||||
.keys()
|
||||
.map(|i| (i.to_string().to_lowercase(), i.possible_values()))
|
||||
.collect::<BTreeMap<_, _>>(),
|
||||
)
|
||||
.into_response()
|
||||
}
|
||||
|
||||
pub async fn vecid_to_vecindexes_handler(State(app_state): State<AppState>) -> Response {
|
||||
axum::Json(app_state.query.vec_trees.serialize_id_to_index_to_vec()).into_response()
|
||||
}
|
||||
|
||||
pub async fn vecindex_to_vecids_handler(State(app_state): State<AppState>) -> Response {
|
||||
axum::Json(app_state.query.vec_trees.serialize_index_to_id_to_vec()).into_response()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user