From 3029dcb2f6edbf2fcc805188ac3883a09715fd3f Mon Sep 17 00:00:00 2001 From: lloydzhou Date: Mon, 30 Sep 2024 15:32:47 +0800 Subject: [PATCH] hotfix for run plugin call post api --- app/utils.ts | 5 ++++- src-tauri/src/stream.rs | 18 +++++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/app/utils.ts b/app/utils.ts index 9f5dd3150..e542e256d 100644 --- a/app/utils.ts +++ b/app/utils.ts @@ -293,7 +293,10 @@ export function fetch( options?: Record, ): Promise { if (window.__TAURI__) { - return tauriStreamFetch(url, options); + return tauriStreamFetch(url, { + ...options, + body: options?.body || options?.data, + }); // const payload = options?.body || options?.data; // return tauriFetch(url, { // ...options, diff --git a/src-tauri/src/stream.rs b/src-tauri/src/stream.rs index 3d21623e6..0fcc02dfc 100644 --- a/src-tauri/src/stream.rs +++ b/src-tauri/src/stream.rs @@ -47,10 +47,10 @@ pub async fn stream_fetch( _headers.insert(key.parse::().unwrap(), value.parse().unwrap()); } - // println!("method: {:?}", method); - // println!("url: {:?}", url); - // println!("headers: {:?}", headers); - // println!("headers: {:?}", _headers); + println!("method: {:?}", method); + println!("url: {:?}", url); + println!("headers: {:?}", headers); + println!("headers: {:?}", _headers); let method = method.parse::().map_err(|err| format!("failed to parse method: {}", err))?; let client = Client::builder() @@ -66,12 +66,12 @@ pub async fn stream_fetch( if method == reqwest::Method::POST || method == reqwest::Method::PUT || method == reqwest::Method::PATCH { let body = bytes::Bytes::from(body); - // println!("body: {:?}", body); + println!("body: {:?}", body); request = request.body(body); } - // println!("client: {:?}", client); - // println!("request: {:?}", request); + println!("client: {:?}", client); + println!("request: {:?}", request); let response_future = request.send(); @@ -94,7 +94,7 @@ pub async fn stream_fetch( while let Some(chunk) = stream.next().await { match chunk { Ok(bytes) => { - // println!("chunk: {:?}", bytes); + println!("chunk: {:?}", bytes); if let Err(e) = window.emit(event_name, ChunkPayload{ request_id, chunk: bytes }) { println!("Failed to emit chunk payload: {:?}", e); } @@ -126,7 +126,7 @@ pub async fn stream_fetch( } } }; - // println!("Response: {:?}", response); + println!("Response: {:?}", response); Ok(response) }