mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 08:46:37 -04:00
allow postrequest to send a binary body; fix WithGraphData
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.
This commit is contained in:
parent
10b7ab2c6d
commit
094c272294
2 changed files with 10 additions and 4 deletions
|
@ -38,9 +38,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
): Promise<void> {
|
||||
await postRequest(
|
||||
"/_anki/setGraphPreferences",
|
||||
new TextDecoder().decode(
|
||||
pb.BackendProto.GraphPreferences.encode(prefs).finish()
|
||||
)
|
||||
pb.BackendProto.GraphPreferences.encode(prefs).finish()
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,17 @@
|
|||
// 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): Promise<Uint8Array> {
|
||||
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) {
|
||||
|
|
Loading…
Reference in a new issue