From a2103959759b6149fefb029f251475e1306d229a Mon Sep 17 00:00:00 2001 From: spacemeowx2 Date: Fri, 21 Oct 2022 11:48:45 +0800 Subject: [PATCH] refactor: remove getWebViewVer --- constant.ts | 2 ++ iksm.ts | 32 +++----------------------------- splatnet3.ts | 9 ++++++--- 3 files changed, 11 insertions(+), 32 deletions(-) diff --git a/constant.ts b/constant.ts index fc60871..ed5b147 100644 --- a/constant.ts +++ b/constant.ts @@ -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) " + diff --git a/iksm.ts b/iksm.ts index 0accaa3..7c6e4fc 100644 --- a/iksm.ts +++ b/iksm.ts @@ -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 { - 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", diff --git a/splatnet3.ts b/splatnet3.ts index 804729e..a783148 100644 --- a/splatnet3.ts +++ b/splatnet3.ts @@ -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( "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",