diff --git a/src/client/http_client.rs b/src/client/http_client.rs index dc94e8f6..ce16ce76 100644 --- a/src/client/http_client.rs +++ b/src/client/http_client.rs @@ -423,6 +423,39 @@ impl BackupClient { self.h2.post(path, param) } + pub fn finish(&self) -> impl Future { + self.h2.clone().post("finish", None).map(|_| ()) + } + + pub fn upload_dynamic_stream( + &self, + archive_name: &str, + stream: impl Stream, + ) -> impl Future { + + let known_chunks = Arc::new(Mutex::new(HashSet::new())); + + let h2 = self.h2.clone(); + let h2_2 = self.h2.clone(); + let h2_3 = self.h2.clone(); + let h2_4 = self.h2.clone(); + + let param = json!({ "archive-name": archive_name }); + + Self::download_chunk_list(h2, "dynamic_index", archive_name, known_chunks.clone()) + .and_then(move |_| { + h2_2.post("dynamic_index", Some(param)) + }) + .and_then(move |res| { + let wid = res.as_u64().unwrap(); + Self::upload_stream(h2_3, wid, stream, known_chunks.clone()) + .and_then(move |_size| { + h2_4.post("dynamic_close", Some(json!({ "wid": wid }))) + }) + .map(|_| ()) + }) + } + fn response_queue() -> ( mpsc::Sender, sync::oneshot::Receiver> @@ -491,39 +524,6 @@ impl BackupClient { }) } - pub fn finish(&self) -> impl Future { - self.h2.clone().post("finish", None).map(|_| ()) - } - - pub fn upload_dynamic_stream( - &self, - archive_name: &str, - stream: impl Stream, - ) -> impl Future { - - let known_chunks = Arc::new(Mutex::new(HashSet::new())); - - let h2 = self.h2.clone(); - let h2_2 = self.h2.clone(); - let h2_3 = self.h2.clone(); - let h2_4 = self.h2.clone(); - - let param = json!({ "archive-name": archive_name }); - - Self::download_chunk_list(h2, "dynamic_index", archive_name, known_chunks.clone()) - .and_then(move |_| { - h2_2.post("dynamic_index", Some(param)) - }) - .and_then(move |res| { - let wid = res.as_u64().unwrap(); - Self::upload_stream(h2_3, wid, stream, known_chunks.clone()) - .and_then(move |_size| { - h2_4.post("dynamic_close", Some(json!({ "wid": wid }))) - }) - .map(|_| ()) - }) - } - fn upload_stream( h2: H2Client, wid: u64,