Fix: multiply the number of bytes by 8

This commit is contained in:
pcmid 2021-10-25 16:39:14 +08:00
parent 967a06a196
commit 188055c812
No known key found for this signature in database
GPG key ID: ABB53028C38EA9E0
2 changed files with 8 additions and 8 deletions

View file

@ -181,10 +181,10 @@ impl ApiInternal {
managed.output_folder managed.output_folder
), ),
AddTorrentResponse::ListOnly(ListOnlyResponse { AddTorrentResponse::ListOnly(ListOnlyResponse {
info_hash, info_hash,
info, info,
only_files, only_files,
}) => ApiAddTorrentResponse { }) => ApiAddTorrentResponse {
id: None, id: None,
details: make_torrent_details(&info_hash, &info, only_files.as_deref()), details: make_torrent_details(&info_hash, &info, only_files.as_deref()),
}, },
@ -221,7 +221,7 @@ impl ApiInternal {
Some(StatsResponse { Some(StatsResponse {
average_piece_download_time: snapshot.average_piece_download_time(), average_piece_download_time: snapshot.average_piece_download_time(),
snapshot, snapshot,
all_time_download_speed: (downloaded_mb / elapsed.as_secs_f64()).into(), all_time_download_speed: (downloaded_mb * 8f64 / elapsed.as_secs_f64()).into(),
download_speed: estimator.download_mbps().into(), download_speed: estimator.download_mbps().into(),
time_remaining: estimator.time_remaining(), time_remaining: estimator.time_remaining(),
}) })
@ -325,7 +325,7 @@ impl HttpApi {
// clippy suggests something that doesn't work here. // clippy suggests something that doesn't work here.
#[allow(clippy::redundant_closure)] #[allow(clippy::redundant_closure)]
move || match inner.dht.as_ref() { move || match inner.dht.as_ref() {
Some(dht) => dht.with_routing_table(|r| json_response(r)), Some(dht) => dht.with_routing_table(|r| json_response(r)),
None => not_found_response("DHT is off".into()), None => not_found_response("DHT is off".into()),
} }
@ -355,7 +355,7 @@ impl HttpApi {
return Ok::<_, warp::Rejection>(make_response( return Ok::<_, warp::Rejection>(make_response(
400, 400,
"invalid utf-8".into(), "invalid utf-8".into(),
)) ));
} }
}; };
let opts = AddTorrentOptions { let opts = AddTorrentOptions {

View file

@ -68,7 +68,7 @@ impl SpeedEstimator {
let downloaded_bytes_diff = downloaded_bytes - first.downloaded_bytes; let downloaded_bytes_diff = downloaded_bytes - first.downloaded_bytes;
let elapsed = instant - first.instant; let elapsed = instant - first.instant;
let bps = downloaded_bytes_diff as f64 / elapsed.as_secs_f64(); let bps = downloaded_bytes_diff as f64 * 8f64 / elapsed.as_secs_f64();
let time_remaining_millis_rounded: u64 = if downloaded_bytes_diff > 0 { let time_remaining_millis_rounded: u64 = if downloaded_bytes_diff > 0 {
let time_remaining_secs = remaining_bytes as f64 / bps; let time_remaining_secs = remaining_bytes as f64 / bps;