@@ -2,8 +2,9 @@ import { useEffect, useState } from "react";
2
2
import { showToast } from "./components/ui-lib" ;
3
3
import Locale from "./locales" ;
4
4
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" ;
7
8
8
9
export function trimTopic ( topic : string ) {
9
10
// Fix an issue where double quotes still show in the Indonesian language
@@ -292,19 +293,22 @@ export function fetch(
292
293
options ?: Record < string , unknown > ,
293
294
) : Promise < any > {
294
295
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);
308
312
}
309
313
return window . fetch ( url , options ) ;
310
314
}
0 commit comments