Simplify cli option, add channel search

This commit is contained in:
Dominik Werder
2021-05-27 16:23:38 +02:00
parent e55751ad67
commit 53957a261a
9 changed files with 155 additions and 22 deletions

View File

@@ -21,6 +21,7 @@ use task::{Context, Poll};
use tracing::field::Empty;
pub mod gather;
pub mod search;
pub async fn host(node_config: NodeConfigCached) -> Result<(), Error> {
let node_config = node_config.clone();
@@ -115,6 +116,13 @@ async fn data_api_proxy_try(req: Request<Body>, node_config: &NodeConfigCached)
} else {
Ok(response(StatusCode::METHOD_NOT_ALLOWED).body(Body::empty())?)
}
} else if path == "/api/4/search/channel" {
if req.method() == Method::GET {
// TODO multi-facility search
Ok(search::channel_search(req, &node_config).await?)
} else {
Ok(response(StatusCode::METHOD_NOT_ALLOWED).body(Body::empty())?)
}
} else if path == "/api/4/table_sizes" {
if req.method() == Method::GET {
Ok(table_sizes(req, &node_config).await?)
@@ -254,7 +262,8 @@ async fn binned(req: Request<Body>, node_config: &NodeConfigCached) -> Result<Re
let query = disk::cache::BinnedQuery::from_request(&head)?;
match head.headers.get("accept") {
Some(v) if v == "application/octet-stream" => binned_binary(query, node_config).await,
_ => binned_json(query, node_config).await,
Some(v) if v == "application/json" => binned_json(query, node_config).await,
_ => Err(Error::with_msg("binned with unknown accept")),
}
}

12
httpret/src/search.rs Normal file
View File

@@ -0,0 +1,12 @@
use err::Error;
use hyper::{Body, Request, Response, StatusCode};
use netpod::{ChannelSearchQuery, NodeConfigCached};
pub async fn channel_search(req: Request<Body>, node_config: &NodeConfigCached) -> Result<Response<Body>, Error> {
let (head, _body) = req.into_parts();
let query = ChannelSearchQuery::from_request(head.uri.query())?;
let res = dbconn::search::search_channel(query, node_config).await?;
let body = Body::from(serde_json::to_string(&res)?);
let ret = super::response(StatusCode::OK).body(body)?;
Ok(ret)
}