lloydzhou 1 год назад
Родитель
Сommit
d51d31a559
1 измененных файлов с 8 добавлено и 26 удалено
  1. 8 26
      app/utils.ts

+ 8 - 26
app/utils.ts

@@ -293,41 +293,23 @@ export function fetch(
   options?: Record<string, unknown>,
 ): Promise<any> {
   if (window.__TAURI__) {
-    return tauriStreamFetch(url, {
-      ...options,
-      body: (options?.body || options?.data) as any,
-    });
-    // const payload = options?.body || options?.data;
-    // return tauriFetch(url, {
-    //   ...options,
-    //   body:
-    //     payload &&
-    //     ({
-    //       type: "Text",
-    //       payload,
-    //     } as any),
-    //   timeout: ((options?.timeout as number) || REQUEST_TIMEOUT_MS) / 1000,
-    //   responseType:
-    //     options?.responseType == "text" ? ResponseType.Text : ResponseType.JSON,
-    // } as any);
+    return tauriStreamFetch(url, options);
   }
   return window.fetch(url, options);
 }
 
 export function adapter(config: Record<string, unknown>) {
-  const { baseURL, url, params, ...rest } = config;
+  const { baseURL, url, params, data: body, ...rest } = config;
   const path = baseURL ? `${baseURL}${url}` : url;
   const fetchUrl = params
     ? `${path}?${new URLSearchParams(params as any).toString()}`
     : path;
-  return fetch(fetchUrl as string, { ...rest, responseType: "text" }).then(
-    (res) => {
-      const { status, headers, statusText } = res;
-      return res
-        .text()
-        .then((data: string) => ({ status, statusText, headers, data }));
-    },
-  );
+  return fetch(fetchUrl as string, { ...rest, body }).then((res) => {
+    const { status, headers, statusText } = res;
+    return res
+      .text()
+      .then((data: string) => ({ status, statusText, headers, data }));
+  });
 }
 
 export function safeLocalStorage(): {