From 70673d24823265928325626b3cf612f796edb68a Mon Sep 17 00:00:00 2001 From: PeterDing Date: Sun, 11 Oct 2020 11:08:40 +0800 Subject: [PATCH] Show process status for directly downloading --- src/app/core/http.rs | 10 +++++++++- src/app/receive/http_receiver.rs | 10 +++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/app/core/http.rs b/src/app/core/http.rs index bdf4440..5241a89 100644 --- a/src/app/core/http.rs +++ b/src/app/core/http.rs @@ -116,6 +116,14 @@ impl HttpHandler { self.uri = uri; + let content_length = { + match cl { + ContentLengthValue::DirectLength(l) => l, + ContentLengthValue::RangeLength(l) => l, + _ => 0, + } + }; + // 2. Compare recorded content length with the above one debug!("HttpHandler: compare recorded content length"); let mut direct = true; @@ -222,7 +230,7 @@ impl HttpHandler { // 5. Create receiver debug!("HttpHandler: create receiver"); - let mut httpreceiver = HttpReceiver::new(&self.output, direct)?; + let mut httpreceiver = HttpReceiver::new(&self.output, direct, content_length)?; httpreceiver.start(receiver).await?; // 6. Task succeeds. Remove rangerecorder file diff --git a/src/app/receive/http_receiver.rs b/src/app/receive/http_receiver.rs index 9fc896f..ad507dc 100644 --- a/src/app/receive/http_receiver.rs +++ b/src/app/receive/http_receiver.rs @@ -23,12 +23,16 @@ pub struct HttpReceiver { } impl HttpReceiver { - pub fn new>(output: P, direct: bool) -> Result { + pub fn new>( + output: P, + direct: bool, + content_length: u64, + ) -> Result { let mut outputfile = File::new(&output, true)?; outputfile.open()?; let (rangerecorder, total, completed) = if direct { - (None, 0, 0) + (None, content_length, 0) } else { let mut rangerecorder = RangeRecorder::new(&*(output.as_ref().to_string_lossy() + RECORDER_FILE_SUFFIX))?; @@ -71,7 +75,7 @@ impl HttpReceiver { let completed = self.ratestatus.total(); let rate = self.ratestatus.rate(); - let eta = if self.rangerecorder.is_some() { + let eta = if self.rangerecorder.is_some() || self.total != 0 { let remains = total - completed; // rate > 1.0 for overflow if remains > 0 && rate > 1.0 {