Simplify cli option, add channel search
This commit is contained in:
@@ -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
12
httpret/src/search.rs
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user