This commit is contained in:
lloydzhou 2024-10-01 14:40:23 +08:00
parent 919ee51dca
commit d51d31a559
1 changed files with 8 additions and 26 deletions

View File

@ -293,41 +293,23 @@ export function fetch(
options?: Record<string, unknown>, options?: Record<string, unknown>,
): Promise<any> { ): Promise<any> {
if (window.__TAURI__) { if (window.__TAURI__) {
return tauriStreamFetch(url, { return tauriStreamFetch(url, options);
...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 window.fetch(url, options); return window.fetch(url, options);
} }
export function adapter(config: Record<string, unknown>) { 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 path = baseURL ? `${baseURL}${url}` : url;
const fetchUrl = params const fetchUrl = params
? `${path}?${new URLSearchParams(params as any).toString()}` ? `${path}?${new URLSearchParams(params as any).toString()}`
: path; : path;
return fetch(fetchUrl as string, { ...rest, responseType: "text" }).then( return fetch(fetchUrl as string, { ...rest, body }).then((res) => {
(res) => { const { status, headers, statusText } = res;
const { status, headers, statusText } = res; return res
return res .text()
.text() .then((data: string) => ({ status, statusText, headers, data }));
.then((data: string) => ({ status, statusText, headers, data })); });
},
);
} }
export function safeLocalStorage(): { export function safeLocalStorage(): {