diff --git a/constant.ts b/constant.ts index e44bcf6..4616739 100644 --- a/constant.ts +++ b/constant.ts @@ -1,3 +1,6 @@ +export const S3SI_VERSION = "0.1.0"; +export const NSOAPP_VERSION = "2.3.1"; +export const USERAGENT = `s3si.ts/${S3SI_VERSION}`; export const DEFAULT_APP_USER_AGENT = "Mozilla/5.0 (Linux; Android 11; Pixel 5) " + "AppleWebKit/537.36 (KHTML, like Gecko) " + diff --git a/deps.ts b/deps.ts index e674c6a..48c0da3 100644 --- a/deps.ts +++ b/deps.ts @@ -6,3 +6,4 @@ export { export * as base64 from "https://deno.land/std@0.160.0/encoding/base64.ts"; export * as flags from "https://deno.land/std@0.160.0/flags/mod.ts"; export * as io from "https://deno.land/std@0.160.0/io/mod.ts"; +export * as uuid from "https://deno.land/std@0.160.0/uuid/mod.ts"; diff --git a/iksm.ts b/iksm.ts index 02c2b8b..502f9b7 100644 --- a/iksm.ts +++ b/iksm.ts @@ -1,7 +1,11 @@ import { CookieJar, wrapFetch } from "./deps.ts"; import { cache, readline, retry, urlBase64Encode } from "./utils.ts"; -import { NSOAPP_VERSION, USERAGENT } from "./version.ts"; -import { DEFAULT_APP_USER_AGENT, SPLATNET3_URL } from "./constant.ts"; +import { + DEFAULT_APP_USER_AGENT, + NSOAPP_VERSION, + SPLATNET3_URL, + USERAGENT, +} from "./constant.ts"; import { APIError } from "./APIError.ts"; export async function loginManually(): Promise { diff --git a/splatnet3.ts b/splatnet3.ts index 10a2a4a..7998bd1 100644 --- a/splatnet3.ts +++ b/splatnet3.ts @@ -2,69 +2,13 @@ import { getWebViewVer } from "./iksm.ts"; import { State } from "./state.ts"; import { DEFAULT_APP_USER_AGENT, SPLATNET3_ENDPOINT } from "./constant.ts"; import { APIError } from "./APIError.ts"; - -enum Queries { - HomeQuery = "dba47124d5ec3090c97ba17db5d2f4b3", - LatestBattleHistoriesQuery = "7d8b560e31617e981cf7c8aa1ca13a00", - RegularBattleHistoriesQuery = "f6e7e0277e03ff14edfef3b41f70cd33", - BankaraBattleHistoriesQuery = "c1553ac75de0a3ea497cdbafaa93e95b", - PrivateBattleHistoriesQuery = "38e0529de8bc77189504d26c7a14e0b8", - VsHistoryDetailQuery = "2b085984f729cd51938fc069ceef784a", - CoopHistoryQuery = "817618ce39bcf5570f52a97d73301b30", - CoopHistoryDetailQuery = "f3799a033f0a7ad4b1b396f9a3bafb1e", -} -type VarsMap = { - [Queries.HomeQuery]: Record; - [Queries.LatestBattleHistoriesQuery]: Record; - [Queries.RegularBattleHistoriesQuery]: Record; - [Queries.BankaraBattleHistoriesQuery]: Record; - [Queries.PrivateBattleHistoriesQuery]: Record; - [Queries.VsHistoryDetailQuery]: { - vsResultId: string; - }; - [Queries.CoopHistoryQuery]: Record; - [Queries.CoopHistoryDetailQuery]: { - coopHistoryDetailId: string; - }; -}; - -type Image = { - url: string; - width?: number; - height?: number; -}; -type RespMap = { - [Queries.HomeQuery]: { - currentPlayer: { - weapon: { - image: Image; - id: string; - }; - }; - banners: { image: Image; message: string; jumpTo: string }[]; - friends: { - nodes: { - id: number; - nickname: string; - userIcon: Image; - }[]; - totalCount: number; - }; - footerMessages: unknown[]; - }; - [Queries.LatestBattleHistoriesQuery]: Record; - [Queries.RegularBattleHistoriesQuery]: Record; - [Queries.BankaraBattleHistoriesQuery]: Record; - [Queries.PrivateBattleHistoriesQuery]: Record; - [Queries.VsHistoryDetailQuery]: Record; - [Queries.CoopHistoryQuery]: Record; - [Queries.CoopHistoryDetailQuery]: Record; -}; -type GraphQLResponse = { - data: T; -} | { - errors: unknown[]; -}; +import { + BattleType, + GraphQLResponse, + Queries, + RespMap, + VarsMap, +} from "./types.ts"; async function request( state: State, @@ -110,7 +54,7 @@ async function request( throw new APIError({ response: resp, json, - message: "Splatnet3 request failed", + message: `Splatnet3 request failed(${json.errors?.[0].message})`, }); } return json.data; @@ -128,3 +72,6 @@ export async function checkToken(state: State) { return true; } + +export async function getBattleList(params: BattleType) { +} diff --git a/types.ts b/types.ts new file mode 100644 index 0000000..889fcc0 --- /dev/null +++ b/types.ts @@ -0,0 +1,123 @@ +export enum Queries { + HomeQuery = "dba47124d5ec3090c97ba17db5d2f4b3", + LatestBattleHistoriesQuery = "7d8b560e31617e981cf7c8aa1ca13a00", + RegularBattleHistoriesQuery = "f6e7e0277e03ff14edfef3b41f70cd33", + BankaraBattleHistoriesQuery = "c1553ac75de0a3ea497cdbafaa93e95b", + PrivateBattleHistoriesQuery = "38e0529de8bc77189504d26c7a14e0b8", + VsHistoryDetailQuery = "2b085984f729cd51938fc069ceef784a", + CoopHistoryQuery = "817618ce39bcf5570f52a97d73301b30", + CoopHistoryDetailQuery = "f3799a033f0a7ad4b1b396f9a3bafb1e", +} +export type VarsMap = { + [Queries.HomeQuery]: Record; + [Queries.LatestBattleHistoriesQuery]: Record; + [Queries.RegularBattleHistoriesQuery]: Record; + [Queries.BankaraBattleHistoriesQuery]: Record; + [Queries.PrivateBattleHistoriesQuery]: Record; + [Queries.VsHistoryDetailQuery]: { + vsResultId: string; + }; + [Queries.CoopHistoryQuery]: Record; + [Queries.CoopHistoryDetailQuery]: { + coopHistoryDetailId: string; + }; +}; + +export type Image = { + url: string; + width?: number; + height?: number; +}; +export type RespMap = { + [Queries.HomeQuery]: { + currentPlayer: { + weapon: { + image: Image; + id: string; + }; + }; + banners: { image: Image; message: string; jumpTo: string }[]; + friends: { + nodes: { + id: number; + nickname: string; + userIcon: Image; + }[]; + totalCount: number; + }; + footerMessages: unknown[]; + }; + [Queries.LatestBattleHistoriesQuery]: Record; + [Queries.RegularBattleHistoriesQuery]: Record; + [Queries.BankaraBattleHistoriesQuery]: { + bankaraBattleHistories: { + summary: { + assistAverage: number; + deathAverage: number; + killAverage: number; + lose: number; + perUnitTimeMinute: number; + specialAverage: number; + win: number; + }; + historyGroups: { + nodes: { + bankaraMatchChallenge: null | { + winCount: number; + loseCount: number; + maxWinCount: number; + maxLoseCount: number; + state: "Failed"; + isPromo: boolean; + isUdemaeUp: boolean; + udemaeAfter: string; + earnedUdemaePoint: number; + }; + historyDetails: { + nodes: { + id: string; + vsMode: { + mode: "BANKARA"; + id: string; + }; + vsRule: { + name: string; + id: string; + }; + vsStage: { + name: string; + id: string; + image: Image; + }; + judgement: "LOSE"; + player: unknown; + }[]; + }; + }[]; + }; + }; + }; + [Queries.PrivateBattleHistoriesQuery]: Record; + [Queries.VsHistoryDetailQuery]: Record; + [Queries.CoopHistoryQuery]: Record; + [Queries.CoopHistoryDetailQuery]: Record; +}; +export type GraphQLResponse = { + data: T; +} | { + errors: { + message: string; + }[]; +}; + +export enum BattleType { + Regular, + Bankara, + Private, +} + +export const BATTLE_QUERY_MAP: Record = { + [BattleType.Regular]: Queries.RegularBattleHistoriesQuery, + [BattleType.Bankara]: Queries.BankaraBattleHistoriesQuery, + [BattleType.Private]: Queries.PrivateBattleHistoriesQuery, +}; diff --git a/version.ts b/version.ts deleted file mode 100644 index f535f66..0000000 --- a/version.ts +++ /dev/null @@ -1,3 +0,0 @@ -export const S3SI_VERSION = "0.1.0"; -export const NSOAPP_VERSION = "2.3.1"; -export const USERAGENT = `s3si.ts/${S3SI_VERSION}`;