also pass rpcenv to async handlers
This commit is contained in:
parent
d2ab5f19e2
commit
e82dad9700
@ -20,7 +20,7 @@ pub trait RpcEnvironment {
|
||||
|
||||
type ApiHandlerFn = fn(Value, &ApiMethod, &mut dyn RpcEnvironment) -> Result<Value, Error>;
|
||||
|
||||
type ApiAsyncHandlerFn = fn(Parts, Body, Value, &ApiAsyncMethod) -> Result<BoxFut, Error>;
|
||||
type ApiAsyncHandlerFn = fn(Parts, Body, Value, &ApiAsyncMethod, &mut dyn RpcEnvironment) -> Result<BoxFut, Error>;
|
||||
|
||||
pub struct ApiMethod {
|
||||
pub parameters: ObjectSchema,
|
||||
|
@ -47,7 +47,13 @@ impl Future for UploadCaTar {
|
||||
}
|
||||
}
|
||||
|
||||
fn upload_catar(parts: Parts, req_body: Body, param: Value, _info: &ApiAsyncMethod) -> Result<BoxFut, Error> {
|
||||
fn upload_catar(
|
||||
parts: Parts,
|
||||
req_body: Body,
|
||||
param: Value,
|
||||
_info: &ApiAsyncMethod,
|
||||
_rpcenv: &mut RpcEnvironment,
|
||||
) -> Result<BoxFut, Error> {
|
||||
|
||||
let store = tools::required_string_param(¶m, "store")?;
|
||||
let archive_name = tools::required_string_param(¶m, "archive_name")?;
|
||||
@ -109,7 +115,13 @@ pub fn api_method_upload_catar() -> ApiAsyncMethod {
|
||||
)
|
||||
}
|
||||
|
||||
fn download_catar(_parts: Parts, _req_body: Body, param: Value, _info: &ApiAsyncMethod) -> Result<BoxFut, Error> {
|
||||
fn download_catar(
|
||||
_parts: Parts,
|
||||
_req_body: Body,
|
||||
param: Value,
|
||||
_info: &ApiAsyncMethod,
|
||||
_rpcenv: &mut RpcEnvironment,
|
||||
) -> Result<BoxFut, Error> {
|
||||
|
||||
let store = tools::required_string_param(¶m, "store")?;
|
||||
let archive_name = tools::required_string_param(¶m, "archive_name")?;
|
||||
|
@ -159,6 +159,7 @@ fn get_request_parameters_async(
|
||||
}
|
||||
|
||||
fn handle_sync_api_request(
|
||||
mut rpcenv: RestEnvironment,
|
||||
info: &'static ApiMethod,
|
||||
formatter: &'static OutputFormatter,
|
||||
parts: Parts,
|
||||
@ -170,7 +171,6 @@ fn handle_sync_api_request(
|
||||
|
||||
let resp = params
|
||||
.and_then(move |params| {
|
||||
let mut rpcenv = RestEnvironment::new();
|
||||
let resp = match (info.handler)(params, info, &mut rpcenv) {
|
||||
Ok(data) => (formatter.format_result)(data, &rpcenv),
|
||||
Err(err) => (formatter.format_error)(err),
|
||||
@ -182,6 +182,7 @@ fn handle_sync_api_request(
|
||||
}
|
||||
|
||||
fn handle_async_api_request(
|
||||
mut rpcenv: RestEnvironment,
|
||||
info: &'static ApiAsyncMethod,
|
||||
formatter: &'static OutputFormatter,
|
||||
parts: Parts,
|
||||
@ -211,7 +212,7 @@ fn handle_async_api_request(
|
||||
}
|
||||
};
|
||||
|
||||
match (info.handler)(parts, req_body, params, info) {
|
||||
match (info.handler)(parts, req_body, params, info, &mut rpcenv) {
|
||||
Ok(future) => future,
|
||||
Err(err) => {
|
||||
let resp = (formatter.format_error)(Error::from(err));
|
||||
@ -396,6 +397,8 @@ pub fn handle_request(api: Arc<ApiConfig>, req: Request<Body>) -> BoxFut {
|
||||
println!("REQUEST {} {}", method, path);
|
||||
println!("COMPO {:?}", components);
|
||||
|
||||
let mut rpcenv = RestEnvironment::new();
|
||||
|
||||
if comp_len >= 1 && components[0] == "api2" {
|
||||
println!("GOT API REQUEST");
|
||||
if comp_len >= 2 {
|
||||
@ -414,10 +417,10 @@ pub fn handle_request(api: Arc<ApiConfig>, req: Request<Body>) -> BoxFut {
|
||||
match api.find_method(&components[2..], method, &mut uri_param) {
|
||||
MethodDefinition::None => {}
|
||||
MethodDefinition::Simple(api_method) => {
|
||||
return handle_sync_api_request(api_method, formatter, parts, body, uri_param);
|
||||
return handle_sync_api_request(rpcenv, api_method, formatter, parts, body, uri_param);
|
||||
}
|
||||
MethodDefinition::Async(async_method) => {
|
||||
return handle_async_api_request(async_method, formatter, parts, body, uri_param);
|
||||
return handle_async_api_request(rpcenv, async_method, formatter, parts, body, uri_param);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user