From cf16af2ab3feaf95668f2800aadb0ee87875eb12 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Wed, 16 Jan 2019 13:58:36 +0100 Subject: [PATCH] server/rest.rs: correctly pass query/url parameters --- src/api3/admin/datastore/upload_catar.rs | 10 ++++++++-- src/server/rest.rs | 14 +++++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/api3/admin/datastore/upload_catar.rs b/src/api3/admin/datastore/upload_catar.rs index 668aa59a..6ae29f8e 100644 --- a/src/api3/admin/datastore/upload_catar.rs +++ b/src/api3/admin/datastore/upload_catar.rs @@ -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.")) ) } diff --git a/src/server/rest.rs b/src/server/rest.rs index d119658d..4ca98815 100644 --- a/src/server/rest.rs +++ b/src/server/rest.rs @@ -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, ) -> 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(¶m_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)); } };