Skip to content

Commit f42488d

Browse files
committed
using stream fetch replace old tauri http fetch
1 parent af49ed4 commit f42488d

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

app/utils.ts

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import { useEffect, useState } from "react";
22
import { showToast } from "./components/ui-lib";
33
import Locale from "./locales";
44
import { RequestMessage } from "./client/api";
5-
import { ServiceProvider, REQUEST_TIMEOUT_MS } from "./constant";
6-
import { fetch as tauriFetch, ResponseType } from "@tauri-apps/api/http";
5+
import { ServiceProvider } from "./constant";
6+
// import { fetch as tauriFetch, ResponseType } from "@tauri-apps/api/http";
7+
import { fetch as tauriStreamFetch } from "./utils/stream";
78

89
export function trimTopic(topic: string) {
910
// Fix an issue where double quotes still show in the Indonesian language
@@ -292,19 +293,22 @@ export function fetch(
292293
options?: Record<string, unknown>,
293294
): Promise<any> {
294295
if (window.__TAURI__) {
295-
const payload = options?.body || options?.data;
296-
return tauriFetch(url, {
297-
...options,
298-
body:
299-
payload &&
300-
({
301-
type: "Text",
302-
payload,
303-
} as any),
304-
timeout: ((options?.timeout as number) || REQUEST_TIMEOUT_MS) / 1000,
305-
responseType:
306-
options?.responseType == "text" ? ResponseType.Text : ResponseType.JSON,
307-
} as any);
296+
return tauriStreamFetch(url, options)
297+
.then((res) => res.text())
298+
.then((data) => ({ data }));
299+
// const payload = options?.body || options?.data;
300+
// return tauriFetch(url, {
301+
// ...options,
302+
// body:
303+
// payload &&
304+
// ({
305+
// type: "Text",
306+
// payload,
307+
// } as any),
308+
// timeout: ((options?.timeout as number) || REQUEST_TIMEOUT_MS) / 1000,
309+
// responseType:
310+
// options?.responseType == "text" ? ResponseType.Text : ResponseType.JSON,
311+
// } as any);
308312
}
309313
return window.fetch(url, options);
310314
}

0 commit comments

Comments
 (0)