fix: wrong base64 encode/decode. fix #4

main
spacemeowx2 2022-10-24 15:15:46 +08:00
parent 1c202e03fa
commit 4a02f6da8c
2 changed files with 14 additions and 7 deletions

View File

@ -318,7 +318,7 @@ async function getSessionToken({
}): Promise<string | undefined> {
const fetch = wrapFetch({ cookieJar });
const res = await fetch(
const resp = await fetch(
"https://accounts.nintendo.com/connect/1.0.0/api/session_token",
{
method: "POST",
@ -338,8 +338,15 @@ async function getSessionToken({
}),
},
);
const resBody = await res.json();
return resBody["session_token"];
const json = await resp.json();
if (json.error) {
throw new APIError({
response: resp,
json,
message: "Error getting session token",
});
}
return json["session_token"];
}
type IminkResponse = {

View File

@ -6,16 +6,16 @@ const stdinLines = io.readLines(Deno.stdin);
export function urlBase64Encode(data: ArrayBuffer) {
return base64.encode(data)
.replaceAll("+", "_")
.replaceAll("/", "-")
.replaceAll("+", "-")
.replaceAll("/", "_")
.replaceAll("=", "");
}
export function urlBase64Decode(data: string) {
return base64.decode(
data
.replaceAll("_", "+")
.replaceAll("-", "/"),
.replaceAll("_", "/")
.replaceAll("-", "+"),
);
}