refactor: remove getWebViewVer

main
spacemeowx2 2022-10-21 11:48:45 +08:00
parent 88aba19a2d
commit a210395975
3 changed files with 11 additions and 32 deletions

View File

@ -3,6 +3,8 @@ import type { StatInkPostBody, VsHistoryDetail } from "./types.ts";
export const AGENT_NAME = "s3si.ts";
export const S3SI_VERSION = "0.1.0";
export const NSOAPP_VERSION = "2.3.1";
export const WEB_VIEW_VERSION = "1.0.0-216d0219";
export const USERAGENT = `${AGENT_NAME}/${S3SI_VERSION}`;
export const DEFAULT_APP_USER_AGENT =
"Mozilla/5.0 (Linux; Android 11; Pixel 5) " +

32
iksm.ts
View File

@ -1,10 +1,10 @@
import { CookieJar, wrapFetch } from "./deps.ts";
import { cache, readline, retry, urlBase64Encode } from "./utils.ts";
import { readline, retry, urlBase64Encode } from "./utils.ts";
import {
DEFAULT_APP_USER_AGENT,
NSOAPP_VERSION,
SPLATNET3_URL,
USERAGENT,
WEB_VIEW_VERSION,
} from "./constant.ts";
import { APIError } from "./APIError.ts";
@ -231,31 +231,6 @@ export async function getGToken(
};
}
async function _getWebViewVer(): Promise<string> {
const splatnet3Home = await (await fetch(SPLATNET3_URL)).text();
const mainJS = /src="(\/.*?\.js)"/.exec(splatnet3Home)?.[1];
if (!mainJS) {
throw new Error("No main.js found");
}
const mainJSBody = await (await fetch(SPLATNET3_URL + mainJS)).text();
const revision = /"([0-9a-f]{40})"/.exec(mainJSBody)?.[1];
const version = /revision_info_not_set.*?="(\d+\.\d+\.\d+)/.exec(mainJSBody)
?.[1];
if (!version || !revision) {
throw new Error("No version and revision found");
}
const ver = `${version}-${revision.substring(0, 8)}`;
return ver;
}
export const getWebViewVer = cache(_getWebViewVer);
export async function getBulletToken(
{
webServiceToken,
@ -269,7 +244,6 @@ export async function getBulletToken(
userCountry: string;
},
) {
const webViewVer = await getWebViewVer();
const resp = await fetch(
"https://api.lp1.av5ja.srv.nintendo.net/api/bullet_tokens",
{
@ -278,7 +252,7 @@ export async function getBulletToken(
"Content-Type": "application/json",
"Accept-Language": userLang,
"User-Agent": appUserAgent,
"X-Web-View-Ver": webViewVer,
"X-Web-View-Ver": WEB_VIEW_VERSION,
"X-NACOUNTRY": userCountry,
"Accept": "*/*",
"Origin": "https://api.lp1.av5ja.srv.nintendo.net",

View File

@ -1,6 +1,9 @@
import { getWebViewVer } from "./iksm.ts";
import { State } from "./state.ts";
import { DEFAULT_APP_USER_AGENT, SPLATNET3_ENDPOINT } from "./constant.ts";
import {
DEFAULT_APP_USER_AGENT,
SPLATNET3_ENDPOINT,
WEB_VIEW_VERSION,
} from "./constant.ts";
import { APIError } from "./APIError.ts";
import {
BattleListType,
@ -33,7 +36,7 @@ async function request<Q extends Queries>(
"Authorization": `Bearer ${state.loginState?.bulletToken}`,
"Accept-Language": state.userLang ?? "en-US",
"User-Agent": state.appUserAgent ?? DEFAULT_APP_USER_AGENT,
"X-Web-View-Ver": await getWebViewVer(),
"X-Web-View-Ver": WEB_VIEW_VERSION,
"Content-Type": "application/json",
"Accept": "*/*",
"Origin": "https://api.lp1.av5ja.srv.nintendo.net",