diff --git a/plugins/upload/guest-js/index.ts b/plugins/upload/guest-js/index.ts index 9586a241..7c5bf796 100644 --- a/plugins/upload/guest-js/index.ts +++ b/plugins/upload/guest-js/index.ts @@ -7,6 +7,7 @@ import { invoke, Channel } from '@tauri-apps/api/core' interface ProgressPayload { progress: number total: number + transferSpeed: number } type ProgressHandler = (progress: ProgressPayload) => void diff --git a/plugins/upload/src/lib.rs b/plugins/upload/src/lib.rs index 45e152f9..6a399fd1 100644 --- a/plugins/upload/src/lib.rs +++ b/plugins/upload/src/lib.rs @@ -58,6 +58,7 @@ impl Serialize for Error { } #[derive(Clone, Serialize)] +#[serde(rename_all = "camelCase")] struct ProgressPayload { progress: u64, total: u64, @@ -150,7 +151,11 @@ fn file_to_body(channel: Channel, file: File) -> reqwest::Body stream, Box::new(move |progress, total| { stats.record_chunk_transfer(progress as usize); - let _ = channel.send(ProgressPayload { progress, total, transfer_speed: stats.transfer_speed }); + let _ = channel.send(ProgressPayload { + progress, + total, + transfer_speed: stats.transfer_speed, + }); }), )) } diff --git a/plugins/upload/src/transfer_stats.rs b/plugins/upload/src/transfer_stats.rs index 83b5b874..41c6f080 100644 --- a/plugins/upload/src/transfer_stats.rs +++ b/plugins/upload/src/transfer_stats.rs @@ -6,7 +6,7 @@ pub struct TransferStats { accumulated_time: u128, // Total time taken for the transfers in the current period pub transfer_speed: u64, // Calculated transfer speed in bytes per second start_time: Instant, // Time when the current period started - granularity: u32, // Time period (in milliseconds) over which the transfer speed is calculated + granularity: u32, // Time period (in milliseconds) over which the transfer speed is calculated } impl TransferStats { @@ -29,7 +29,8 @@ impl TransferStats { // If the accumulated time exceeds the granularity, calculate the transfer speed. if self.accumulated_time >= self.granularity as u128 { - self.transfer_speed = (self.accumulated_chunk_len as u128 / self.accumulated_time * 1024) as u64; + self.transfer_speed = + (self.accumulated_chunk_len as u128 / self.accumulated_time * 1024) as u64; self.accumulated_chunk_len = 0; self.accumulated_time = 0; } @@ -44,4 +45,4 @@ impl Default for TransferStats { fn default() -> Self { Self::start(500) // Default granularity is 500 } -} \ No newline at end of file +}