mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-28 16:49:58 -07:00
bitview: reorg part 10 + api changes
This commit is contained in:
@@ -5,7 +5,7 @@ use axum::{
|
||||
response::{IntoResponse, Response},
|
||||
routing::get,
|
||||
};
|
||||
use brk_interface::{Index, PaginatedIndexParam, PaginationParam, Params, ParamsOpt};
|
||||
use brk_interface::{Index, PaginatedIndexParam, PaginationParam, Params, ParamsDeprec, ParamsOpt};
|
||||
|
||||
use super::AppState;
|
||||
|
||||
@@ -35,26 +35,26 @@ impl ApiMetricsRoutes for Router<AppState> {
|
||||
Json(app_state.interface.get_accepted_indexes()).into_response()
|
||||
}),
|
||||
)
|
||||
.route(
|
||||
"/api/vecs/metrics",
|
||||
get(
|
||||
async |State(app_state): State<AppState>,
|
||||
Query(pagination): Query<PaginationParam>|
|
||||
-> Response {
|
||||
Json(app_state.interface.get_metrics(pagination)).into_response()
|
||||
},
|
||||
),
|
||||
)
|
||||
.route(
|
||||
"/api/vecs/index-to-metrics",
|
||||
get(
|
||||
async |State(app_state): State<AppState>,
|
||||
Query(paginated_index): Query<PaginatedIndexParam>|
|
||||
-> Response {
|
||||
Json(app_state.interface.get_index_to_vecids(paginated_index)).into_response()
|
||||
},
|
||||
),
|
||||
)
|
||||
// .route(
|
||||
// "/api/vecs/metrics",
|
||||
// get(
|
||||
// async |State(app_state): State<AppState>,
|
||||
// Query(pagination): Query<PaginationParam>|
|
||||
// -> Response {
|
||||
// Json(app_state.interface.get_metrics(pagination)).into_response()
|
||||
// },
|
||||
// ),
|
||||
// )
|
||||
// .route(
|
||||
// "/api/vecs/index-to-metrics",
|
||||
// get(
|
||||
// async |State(app_state): State<AppState>,
|
||||
// Query(paginated_index): Query<PaginatedIndexParam>|
|
||||
// -> Response {
|
||||
// Json(app_state.interface.get_index_to_vecids(paginated_index)).into_response()
|
||||
// },
|
||||
// ),
|
||||
// )
|
||||
.route(
|
||||
"/api/metrics/{metric}",
|
||||
get(
|
||||
@@ -64,25 +64,44 @@ impl ApiMetricsRoutes for Router<AppState> {
|
||||
},
|
||||
),
|
||||
)
|
||||
.route("/api/metrics/bulk", get(data::handler))
|
||||
.route(
|
||||
"/api/metrics/{metric}/{index}",
|
||||
get(
|
||||
async |State(app_state): State<AppState>,
|
||||
Path((metric, index)): Path<(String, Index)>|
|
||||
async |uri: Uri,
|
||||
headers: HeaderMap,
|
||||
state: State<AppState>,
|
||||
Path((metric, index)): Path<(String, Index)>,
|
||||
Query(params_opt): Query<ParamsOpt>|
|
||||
-> Response {
|
||||
// If not found do fuzzy search but here or in interface ?
|
||||
Json(
|
||||
format!("{metric}/{index}"), // app_state
|
||||
// .interface
|
||||
// .metric_to_indexes(metric.replace("-", "_")),
|
||||
data::handler(
|
||||
uri,
|
||||
headers,
|
||||
Query(Params::from(((index, metric), params_opt))),
|
||||
state,
|
||||
)
|
||||
.into_response()
|
||||
.await
|
||||
},
|
||||
),
|
||||
)
|
||||
// !!!
|
||||
// DEPRECATED
|
||||
.route("/api/vecs/query", get(data::handler))
|
||||
// !!!
|
||||
.route(
|
||||
"/api/vecs/query",
|
||||
get(
|
||||
async |uri: Uri,
|
||||
headers: HeaderMap,
|
||||
Query(params): Query<ParamsDeprec>,
|
||||
state: State<AppState>|
|
||||
-> Response {
|
||||
data::handler(uri, headers, Query(params.into()), state).await
|
||||
},
|
||||
),
|
||||
)
|
||||
// !!!
|
||||
// DEPRECATED
|
||||
// !!!
|
||||
.route(
|
||||
"/api/vecs/{variant}",
|
||||
get(
|
||||
@@ -95,15 +114,16 @@ impl ApiMetricsRoutes for Router<AppState> {
|
||||
let variant = variant.replace("-", "_");
|
||||
let mut split = variant.split(TO_SEPARATOR);
|
||||
|
||||
if let Ok(index) = Index::try_from(split.next().unwrap()) {
|
||||
let params = Params::from((
|
||||
(index, split.collect::<Vec<_>>().join(TO_SEPARATOR)),
|
||||
params_opt,
|
||||
));
|
||||
data::handler(uri, headers, Query(params), state).await
|
||||
} else {
|
||||
"Bad variant".into_response()
|
||||
}
|
||||
let ser_index = split.next().unwrap();
|
||||
let Ok(index) = Index::try_from(ser_index) else {
|
||||
return format!("Index {ser_index} doesn't exist").into_response();
|
||||
};
|
||||
|
||||
let params = Params::from((
|
||||
(index, split.collect::<Vec<_>>().join(TO_SEPARATOR)),
|
||||
params_opt,
|
||||
));
|
||||
data::handler(uri, headers, Query(params), state).await
|
||||
},
|
||||
),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user