refactor(http): migrate to tauri's new resource table (#834)

* refactor(http): migrate to tauri's new resource table

* fmt

* change file
This commit is contained in:
Amr Bashir
2024-01-02 21:55:57 +02:00
committed by GitHub
parent ea8eadce85
commit ae0cb92438
6 changed files with 68 additions and 75 deletions
+14 -8
View File
@@ -113,6 +113,8 @@ export async function fetch(
delete init.proxy;
}
const signal = init?.signal;
const req = new Request(input, init);
const buffer = await req.arrayBuffer();
const reqData = buffer.byteLength ? Array.from(new Uint8Array(buffer)) : null;
@@ -129,7 +131,7 @@ export async function fetch(
},
});
req.signal.addEventListener("abort", () => {
signal?.addEventListener("abort", () => {
invoke("plugin:http|fetch_cancel", {
rid,
});
@@ -140,17 +142,21 @@ export async function fetch(
statusText: string;
headers: [[string, string]];
url: string;
rid: number;
}
const { status, statusText, url, headers } = await invoke<FetchSendResponse>(
"plugin:http|fetch_send",
{
rid,
},
);
const {
status,
statusText,
url,
headers,
rid: responseRid,
} = await invoke<FetchSendResponse>("plugin:http|fetch_send", {
rid,
});
const body = await invoke<number[]>("plugin:http|fetch_read_body", {
rid,
rid: responseRid,
});
const res = new Response(new Uint8Array(body), {