feat: add Queries fetch in update-constant
parent
feb486e775
commit
c2f42863b8
|
|
@ -30,6 +30,62 @@ function getConst(content: string, name: string): string {
|
||||||
return JSON.parse(match[1]);
|
return JSON.parse(match[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function replaceEnum(
|
||||||
|
content: string,
|
||||||
|
name: string,
|
||||||
|
pairs: Record<string, string>,
|
||||||
|
): string {
|
||||||
|
const regex = new RegExp(`export enum ${name} {([\\s\\S^}]+?)}`);
|
||||||
|
|
||||||
|
const body = Object.entries(pairs).map(([key, value]) =>
|
||||||
|
` ${key} = "${value}"`
|
||||||
|
).join(",\n");
|
||||||
|
|
||||||
|
return content.replace(regex, `export enum ${name} {\n${body}\n}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getEnumKeys(content: string, name: string): string[] {
|
||||||
|
const regex = new RegExp(`export enum ${name} {([\\s\\S^}]+?)}`);
|
||||||
|
|
||||||
|
const match = regex.exec(content);
|
||||||
|
|
||||||
|
if (!match) {
|
||||||
|
throw new Error(`Cannot find ${name}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
const body = match[1];
|
||||||
|
|
||||||
|
// extract keys from `key = "value"`
|
||||||
|
const keys: string[] = [];
|
||||||
|
const keyRE = /\s*(\w+)\s*=/g;
|
||||||
|
while (true) {
|
||||||
|
const match = keyRE.exec(body);
|
||||||
|
if (!match) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
keys.push(match[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return keys;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getQueryHash(js: string, query: string): string {
|
||||||
|
const regex = new RegExp(
|
||||||
|
`params:\\{id:"([^"]*?)",metadata:{},name:"${query}"`,
|
||||||
|
);
|
||||||
|
|
||||||
|
const match = regex.exec(js);
|
||||||
|
|
||||||
|
if (!match) {
|
||||||
|
throw new Error(`Cannot find ${query}`);
|
||||||
|
}
|
||||||
|
if (match[0].length > 500) {
|
||||||
|
throw new Error(`Match too large ${match[0].length}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return match[1];
|
||||||
|
}
|
||||||
|
|
||||||
async function printError<T>(p: Promise<T>): Promise<T | undefined> {
|
async function printError<T>(p: Promise<T>): Promise<T | undefined> {
|
||||||
try {
|
try {
|
||||||
return await p;
|
return await p;
|
||||||
|
|
@ -39,7 +95,7 @@ async function printError<T>(p: Promise<T>): Promise<T | undefined> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getWebViewVer(): Promise<string> {
|
async function getMainJSBody(): Promise<string> {
|
||||||
const splatnet3Home = await (await fetch(SPLATNET3_URL)).text();
|
const splatnet3Home = await (await fetch(SPLATNET3_URL)).text();
|
||||||
|
|
||||||
const mainJS = /src="(\/.*?\.js)"/.exec(splatnet3Home)?.[1];
|
const mainJS = /src="(\/.*?\.js)"/.exec(splatnet3Home)?.[1];
|
||||||
|
|
@ -50,9 +106,16 @@ async function getWebViewVer(): Promise<string> {
|
||||||
|
|
||||||
const mainJSBody = await (await fetch(SPLATNET3_URL + mainJS)).text();
|
const mainJSBody = await (await fetch(SPLATNET3_URL + mainJS)).text();
|
||||||
|
|
||||||
const revision = /"([0-9a-f]{40})"/.exec(mainJSBody)?.[1];
|
return mainJSBody;
|
||||||
|
}
|
||||||
|
|
||||||
|
const mainJSBody = await getMainJSBody();
|
||||||
|
|
||||||
|
// deno-lint-ignore require-await
|
||||||
|
async function getWebViewVer(js: string): Promise<string> {
|
||||||
|
const revision = /"([0-9a-f]{40})"/.exec(js)?.[1];
|
||||||
const version = /revision_info_not_set.*?=("|`)(\d+\.\d+\.\d+)-/.exec(
|
const version = /revision_info_not_set.*?=("|`)(\d+\.\d+\.\d+)-/.exec(
|
||||||
mainJSBody,
|
js,
|
||||||
)
|
)
|
||||||
?.[2];
|
?.[2];
|
||||||
|
|
||||||
|
|
@ -83,7 +146,7 @@ const oldValues = {
|
||||||
};
|
};
|
||||||
const newValues: Record<string, string | undefined> = {};
|
const newValues: Record<string, string | undefined> = {};
|
||||||
|
|
||||||
newValues.WEB_VIEW_VERSION = await printError(getWebViewVer());
|
newValues.WEB_VIEW_VERSION = await printError(getWebViewVer(mainJSBody));
|
||||||
newValues.NSOAPP_VERSION = await printError(getNSOVer());
|
newValues.NSOAPP_VERSION = await printError(getNSOVer());
|
||||||
|
|
||||||
for (const [key, value] of Object.entries(newValues)) {
|
for (const [key, value] of Object.entries(newValues)) {
|
||||||
|
|
@ -91,8 +154,27 @@ for (const [key, value] of Object.entries(newValues)) {
|
||||||
content = replaceConst(content, key, value);
|
content = replaceConst(content, key, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await Deno.writeTextFile(CONSTANT_PATH, content);
|
|
||||||
|
|
||||||
console.log("Done");
|
console.log("const updated");
|
||||||
console.log("Old:", oldValues);
|
console.log("Old:", oldValues);
|
||||||
console.log("New:", newValues);
|
console.log("New:", newValues);
|
||||||
|
|
||||||
|
const keys = getEnumKeys(content, "Queries");
|
||||||
|
const pairs = Object.fromEntries(
|
||||||
|
keys.map((key) => [key, getQueryHash(mainJSBody, key)]),
|
||||||
|
);
|
||||||
|
content = replaceEnum(content, "Queries", pairs);
|
||||||
|
console.log("query updated");
|
||||||
|
|
||||||
|
await Deno.writeTextFile(CONSTANT_PATH, content);
|
||||||
|
|
||||||
|
const command = new Deno.Command(Deno.execPath(), {
|
||||||
|
args: ["fmt", "./src/constant.ts"],
|
||||||
|
cwd: ROOT_DIR,
|
||||||
|
stdin: "inherit",
|
||||||
|
stdout: "inherit",
|
||||||
|
});
|
||||||
|
const { code } = command.outputSync();
|
||||||
|
if (code !== 0) {
|
||||||
|
Deno.exit(code);
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,22 @@ export const AGENT_NAME = "s3si.ts";
|
||||||
export const S3SI_VERSION = "0.3.5";
|
export const S3SI_VERSION = "0.3.5";
|
||||||
export const NSOAPP_VERSION = "2.5.1";
|
export const NSOAPP_VERSION = "2.5.1";
|
||||||
export const WEB_VIEW_VERSION = "3.0.0-0742bda0";
|
export const WEB_VIEW_VERSION = "3.0.0-0742bda0";
|
||||||
|
export enum Queries {
|
||||||
|
HomeQuery = "22e2fa8294168003c21b00c333c35384",
|
||||||
|
LatestBattleHistoriesQuery = "0176a47218d830ee447e10af4a287b3f",
|
||||||
|
RegularBattleHistoriesQuery = "3baef04b095ad8975ea679d722bc17de",
|
||||||
|
BankaraBattleHistoriesQuery = "0438ea6978ae8bd77c5d1250f4f84803",
|
||||||
|
XBattleHistoriesQuery = "6796e3cd5dc3ebd51864dc709d899fc5",
|
||||||
|
PrivateBattleHistoriesQuery = "8e5ae78b194264a6c230e262d069bd28",
|
||||||
|
VsHistoryDetailQuery = "291295ad311b99a6288fc95a5c4cb2d2",
|
||||||
|
CoopHistoryQuery = "91b917becd2fa415890f5b47e15ffb15",
|
||||||
|
CoopHistoryDetailQuery = "379f0d9b78b531be53044bcac031b34b",
|
||||||
|
myOutfitCommonDataFilteringConditionQuery =
|
||||||
|
"d02ab22c9dccc440076055c8baa0fa7a",
|
||||||
|
myOutfitCommonDataEquipmentsQuery = "d29cd0c2b5e6bac90dd5b817914832f8",
|
||||||
|
HistoryRecordQuery = "f09da9d24d888797fdfb2f060dbdf4ed",
|
||||||
|
ConfigureAnalyticsQuery = "f8ae00773cc412a50dd41a6d9a159ddd",
|
||||||
|
}
|
||||||
export const S3SI_LINK = "https://github.com/spacemeowx2/s3si.ts";
|
export const S3SI_LINK = "https://github.com/spacemeowx2/s3si.ts";
|
||||||
|
|
||||||
export const USERAGENT = `${AGENT_NAME}/${S3SI_VERSION} (${S3SI_LINK})`;
|
export const USERAGENT = `${AGENT_NAME}/${S3SI_VERSION} (${S3SI_LINK})`;
|
||||||
|
|
|
||||||
18
src/types.ts
18
src/types.ts
|
|
@ -1,21 +1,7 @@
|
||||||
import { RankState } from "./state.ts";
|
import { RankState } from "./state.ts";
|
||||||
|
import { Queries } from "./constant.ts";
|
||||||
|
export { Queries };
|
||||||
|
|
||||||
export enum Queries {
|
|
||||||
HomeQuery = "22e2fa8294168003c21b00c333c35384",
|
|
||||||
LatestBattleHistoriesQuery = "0176a47218d830ee447e10af4a287b3f",
|
|
||||||
RegularBattleHistoriesQuery = "3baef04b095ad8975ea679d722bc17de",
|
|
||||||
BankaraBattleHistoriesQuery = "0438ea6978ae8bd77c5d1250f4f84803",
|
|
||||||
XBattleHistoriesQuery = "6796e3cd5dc3ebd51864dc709d899fc5",
|
|
||||||
PrivateBattleHistoriesQuery = "8e5ae78b194264a6c230e262d069bd28",
|
|
||||||
VsHistoryDetailQuery = "291295ad311b99a6288fc95a5c4cb2d2",
|
|
||||||
CoopHistoryQuery = "91b917becd2fa415890f5b47e15ffb15",
|
|
||||||
CoopHistoryDetailQuery = "379f0d9b78b531be53044bcac031b34b",
|
|
||||||
myOutfitCommonDataFilteringConditionQuery =
|
|
||||||
"d02ab22c9dccc440076055c8baa0fa7a",
|
|
||||||
myOutfitCommonDataEquipmentsQuery = "d29cd0c2b5e6bac90dd5b817914832f8",
|
|
||||||
HistoryRecordQuery = "f09da9d24d888797fdfb2f060dbdf4ed",
|
|
||||||
ConfigureAnalyticsQuery = "f8ae00773cc412a50dd41a6d9a159ddd",
|
|
||||||
}
|
|
||||||
export type VarsMap = {
|
export type VarsMap = {
|
||||||
[Queries.HomeQuery]: [];
|
[Queries.HomeQuery]: [];
|
||||||
[Queries.LatestBattleHistoriesQuery]: [];
|
[Queries.LatestBattleHistoriesQuery]: [];
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue