hotfix for run plugin call post api

This commit is contained in:
lloydzhou 2024-09-30 15:32:47 +08:00
parent 35e03e1bca
commit 3029dcb2f6
2 changed files with 13 additions and 10 deletions

View File

@ -293,7 +293,10 @@ export function fetch(
options?: Record<string, unknown>, options?: Record<string, unknown>,
): Promise<any> { ): Promise<any> {
if (window.__TAURI__) { if (window.__TAURI__) {
return tauriStreamFetch(url, options); return tauriStreamFetch(url, {
...options,
body: options?.body || options?.data,
});
// const payload = options?.body || options?.data; // const payload = options?.body || options?.data;
// return tauriFetch(url, { // return tauriFetch(url, {
// ...options, // ...options,

View File

@ -47,10 +47,10 @@ pub async fn stream_fetch(
_headers.insert(key.parse::<HeaderName>().unwrap(), value.parse().unwrap()); _headers.insert(key.parse::<HeaderName>().unwrap(), value.parse().unwrap());
} }
// println!("method: {:?}", method); println!("method: {:?}", method);
// println!("url: {:?}", url); println!("url: {:?}", url);
// println!("headers: {:?}", headers); println!("headers: {:?}", headers);
// println!("headers: {:?}", _headers); println!("headers: {:?}", _headers);
let method = method.parse::<reqwest::Method>().map_err(|err| format!("failed to parse method: {}", err))?; let method = method.parse::<reqwest::Method>().map_err(|err| format!("failed to parse method: {}", err))?;
let client = Client::builder() 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 { if method == reqwest::Method::POST || method == reqwest::Method::PUT || method == reqwest::Method::PATCH {
let body = bytes::Bytes::from(body); let body = bytes::Bytes::from(body);
// println!("body: {:?}", body); println!("body: {:?}", body);
request = request.body(body); request = request.body(body);
} }
// println!("client: {:?}", client); println!("client: {:?}", client);
// println!("request: {:?}", request); println!("request: {:?}", request);
let response_future = request.send(); let response_future = request.send();
@ -94,7 +94,7 @@ pub async fn stream_fetch(
while let Some(chunk) = stream.next().await { while let Some(chunk) = stream.next().await {
match chunk { match chunk {
Ok(bytes) => { Ok(bytes) => {
// println!("chunk: {:?}", bytes); println!("chunk: {:?}", bytes);
if let Err(e) = window.emit(event_name, ChunkPayload{ request_id, chunk: bytes }) { if let Err(e) = window.emit(event_name, ChunkPayload{ request_id, chunk: bytes }) {
println!("Failed to emit chunk payload: {:?}", e); println!("Failed to emit chunk payload: {:?}", e);
} }
@ -126,7 +126,7 @@ pub async fn stream_fetch(
} }
} }
}; };
// println!("Response: {:?}", response); println!("Response: {:?}", response);
Ok(response) Ok(response)
} }