server/rest.rs: correctly pass query/url parameters

This commit is contained in:
Dietmar Maurer 2019-01-16 13:58:36 +01:00
parent 2085142ed4
commit cf16af2ab3
2 changed files with 19 additions and 5 deletions

View File

@ -9,6 +9,7 @@ use crate::api::router::*;
use serde_json::Value;
use std::io::Write;
use futures::*;
use std::path::PathBuf;
pub struct UploadCaTar {
stream: hyper::Body,
@ -42,13 +43,17 @@ impl Future for UploadCaTar {
fn upload_catar(req_body: hyper::Body, param: Value, _info: &ApiUploadMethod) -> BoxFut {
let store = param["name"].as_str().unwrap();
let archive_name = param["archive_name"].as_str().unwrap();
println!("Upload .catar to {}", store);
println!("Upload {}.catar to {} ({}.aidx)", archive_name, store, archive_name);
let chunk_size = 4*1024*1024;
let datastore = DataStore::lookup_datastore(store).unwrap().clone();
let index = datastore.create_archive_writer("upload.aidx", chunk_size).unwrap();
let mut full_archive_name = PathBuf::from(archive_name);
full_archive_name.set_extension("aidx");
let index = datastore.create_archive_writer(&full_archive_name, chunk_size).unwrap();
let upload = UploadCaTar { stream: req_body, index, count: 0};
@ -70,5 +75,6 @@ pub fn api_method_upload_catar() -> ApiUploadMethod {
upload_catar,
ObjectSchema::new("Upload .catar backup file.")
.required("name", StringSchema::new("Datastore name."))
.required("archive_name", StringSchema::new("Backup archive name."))
)
}

View File

@ -180,8 +180,8 @@ fn handle_sync_api_request(
fn handle_upload_api_request(
info: &'static ApiUploadMethod,
_formatter: &'static OutputFormatter,
_parts: Parts,
formatter: &'static OutputFormatter,
parts: Parts,
req_body: Body,
uri_param: HashMap<String, String>,
) -> BoxFut
@ -189,6 +189,13 @@ fn handle_upload_api_request(
// fixme: convert parameters to Json
let mut param_list: Vec<(String, String)> = vec![];
if let Some(query_str) = parts.uri.query() {
for (k, v) in form_urlencoded::parse(query_str.as_bytes()).into_owned() {
if k == "_dc" { continue; } // skip extjs "disable cache" parameter
param_list.push((k, v));
}
}
for (k, v) in uri_param {
param_list.push((k.clone(), v.clone()));
}
@ -196,7 +203,8 @@ fn handle_upload_api_request(
let params = match parse_parameter_strings(&param_list, &info.parameters, true) {
Ok(v) => v,
Err(err) => {
return Box::new(future::err(err.into()));
let resp = (formatter.format_result)(Err(Error::from(err)));
return Box::new(future::ok(resp));
}
};