094c272294
As far as I can tell, the existing code was transforming the encoded protobuf data into UTF8, and we're just lucky it wasn't causing problems with the small message we were sending.
27 lines
775 B
TypeScript
27 lines
775 B
TypeScript
// Copyright: Ankitects Pty Ltd and contributors
|
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
|
|
export async function postRequest(
|
|
path: string,
|
|
body: string | Uint8Array
|
|
): Promise<Uint8Array> {
|
|
const headers = {};
|
|
if (body instanceof Uint8Array) {
|
|
headers["Content-type"] = "application/octet-stream";
|
|
}
|
|
const resp = await fetch(path, {
|
|
method: "POST",
|
|
headers,
|
|
body,
|
|
});
|
|
if (!resp.ok) {
|
|
const body = await resp.text();
|
|
throw Error(`${resp.status}: ${body}`);
|
|
}
|
|
// get returned bytes
|
|
const respBlob = await resp.blob();
|
|
const respBuf = await new Response(respBlob).arrayBuffer();
|
|
const bytes = new Uint8Array(respBuf);
|
|
return bytes;
|
|
}
|