From ca3651b55d5a144757a620eab2dba6b2f7abc10f Mon Sep 17 00:00:00 2001 From: adrieljss Date: Mon, 3 Mar 2025 12:37:46 +0800 Subject: [PATCH] fix(stream): change IPC packet --- Cargo.lock | 20 +++++++++++++++----- plugins/http/Cargo.toml | 1 + plugins/http/src/commands.rs | 12 +++++------- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1154189d..c7ecb516 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1847,7 +1847,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d" dependencies = [ "libc", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -3349,7 +3349,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34" dependencies = [ "cfg-if", - "windows-targets 0.48.5", + "windows-targets 0.52.6", ] [[package]] @@ -4840,7 +4840,7 @@ dependencies = [ "once_cell", "socket2", "tracing", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -5524,6 +5524,15 @@ dependencies = [ "typeid", ] +[[package]] +name = "serde_bytes" +version = "0.11.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "387cc504cb06bb40a96c8e04e951fe01854cf6bc921053c954e4a606d9675c6a" +dependencies = [ + "serde", +] + [[package]] name = "serde_derive" version = "1.0.215" @@ -6667,6 +6676,7 @@ dependencies = [ "reqwest", "schemars", "serde", + "serde_bytes", "serde_json", "tauri", "tauri-plugin", @@ -7096,7 +7106,7 @@ dependencies = [ "fastrand", "once_cell", "rustix", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -8126,7 +8136,7 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" dependencies = [ - "windows-sys 0.48.0", + "windows-sys 0.59.0", ] [[package]] diff --git a/plugins/http/Cargo.toml b/plugins/http/Cargo.toml index 9aa49e0e..d37d418e 100644 --- a/plugins/http/Cargo.toml +++ b/plugins/http/Cargo.toml @@ -30,6 +30,7 @@ regex = "1" [dependencies] serde = { workspace = true } +serde_bytes = "0.11" serde_json = { workspace = true } tauri = { workspace = true } thiserror = { workspace = true } diff --git a/plugins/http/src/commands.rs b/plugins/http/src/commands.rs index b0c6aab7..1a86da57 100644 --- a/plugins/http/src/commands.rs +++ b/plugins/http/src/commands.rs @@ -131,8 +131,8 @@ pub struct BasicAuth { #[derive(Clone, Serialize)] pub struct StreamMessage { - value: Option>, - done: bool, + #[serde(with = "serde_bytes")] + bytes: Vec } #[inline] @@ -329,13 +329,11 @@ pub async fn fetch( // send response through IPC channel while let Some(chunk) = res.chunk().await? { - stream_channel.send(StreamMessage{ - value: Some(chunk.to_vec()), - done: false, - })?; + stream_channel.send(StreamMessage{bytes: chunk.to_vec()})?; } - stream_channel.send(StreamMessage { value: None, done: true })?; + // send empty vector when done + stream_channel.send(StreamMessage{bytes: Vec::new()})?; // return that response Ok(res)