feat: add fetch from all modes

dumb-splashcat-thing
spacemeowx2 2023-06-06 19:37:52 +08:00 committed by imspace
parent 8a96cb321c
commit 91f528a3be
6 changed files with 55 additions and 19 deletions

View File

@ -32,8 +32,7 @@ Options:
(e.g. "stat.ink,file") (e.g. "stat.ink,file")
--list-method When set to "latest", the latest 50 matches will be obtained. --list-method When set to "latest", the latest 50 matches will be obtained.
When set to "all", matches of all modes will be obtained with a maximum of 250 matches (5 modes x 50 matches). When set to "all", matches of all modes will be obtained with a maximum of 250 matches (5 modes x 50 matches).
When set to "auto", the latest 50 matches will be obtained. If 50 matches have not been uploaded yet, matches will be obtained from the list of all modes. "latest" is the default setting.
"auto" is the default setting.
--no-progress, -n Disable progress bar --no-progress, -n Disable progress bar
--monitor, -m Monitor mode --monitor, -m Monitor mode
--skip-mode <mode>, -s Skip mode (default: null) --skip-mode <mode>, -s Skip mode (default: null)

View File

@ -5,7 +5,7 @@ import {
HistoryGroups, HistoryGroups,
RankParam, RankParam,
} from "./types.ts"; } from "./types.ts";
import { gameId, parseHistoryDetailId } from "./utils.ts"; import { battleTime, gameId } from "./utils.ts";
import { getSeason } from "./VersionData.ts"; import { getSeason } from "./VersionData.ts";
const splusParams = () => { const splusParams = () => {
@ -193,17 +193,6 @@ function addRank(
}; };
} }
const battleTime = (id: string) => {
const { timestamp } = parseHistoryDetailId(id);
const dateStr = timestamp.replace(
/(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})(\d{2})/,
"$1-$2-$3T$4:$5:$6Z",
);
return new Date(dateStr);
};
type FlattenItem = { type FlattenItem = {
id: string; id: string;
gameId: string; gameId: string;

View File

@ -10,8 +10,6 @@ import { delay, showError } from "./utils.ts";
import { GameFetcher } from "./GameFetcher.ts"; import { GameFetcher } from "./GameFetcher.ts";
import { DEFAULT_ENV, Env } from "./env.ts"; import { DEFAULT_ENV, Env } from "./env.ts";
export type ListMethod = "latest" | "all" | "auto";
export type Opts = { export type Opts = {
profilePath: string; profilePath: string;
exporter: string; exporter: string;
@ -31,7 +29,7 @@ export const DEFAULT_OPTS: Opts = {
noProgress: false, noProgress: false,
monitor: false, monitor: false,
withSummary: false, withSummary: false,
listMethod: "auto", listMethod: "latest",
env: DEFAULT_ENV, env: DEFAULT_ENV,
}; };
@ -167,7 +165,12 @@ export class App {
this.env.logger.log("Skip exporting VS games."); this.env.logger.log("Skip exporting VS games.");
} else { } else {
this.env.logger.log("Fetching battle list..."); this.env.logger.log("Fetching battle list...");
const gameList = await splatnet.getBattleList(); let gameList: string[];
if (this.opts.listMethod === "all") {
gameList = await splatnet.getAllBattleList();
} else {
gameList = await splatnet.getBattleList();
}
const { redraw, endBar } = this.exporterProgress("Export vs games"); const { redraw, endBar } = this.exporterProgress("Export vs games");
const fetcher = new GameFetcher({ const fetcher = new GameFetcher({

View File

@ -15,7 +15,7 @@ import {
} from "./types.ts"; } from "./types.ts";
import { DEFAULT_ENV, Env } from "./env.ts"; import { DEFAULT_ENV, Env } from "./env.ts";
import { getBulletToken, getGToken } from "./iksm.ts"; import { getBulletToken, getGToken } from "./iksm.ts";
import { parseHistoryDetailId } from "./utils.ts"; import { battleTime, parseHistoryDetailId } from "./utils.ts";
export class Splatnet3 { export class Splatnet3 {
protected profile: Profile; protected profile: Profile;
@ -137,6 +137,12 @@ export class Splatnet3 {
[BattleListType.Bankara]: () => [BattleListType.Bankara]: () =>
this.request(Queries.BankaraBattleHistoriesQuery) this.request(Queries.BankaraBattleHistoriesQuery)
.then((r) => getIdsFromGroups(r.bankaraBattleHistories)), .then((r) => getIdsFromGroups(r.bankaraBattleHistories)),
[BattleListType.XBattle]: () =>
this.request(Queries.XBattleHistoriesQuery)
.then((r) => getIdsFromGroups(r.xBattleHistories)),
[BattleListType.Event]: () =>
this.request(Queries.EventBattleHistoriesQuery)
.then((r) => getIdsFromGroups(r.eventBattleHistories)),
[BattleListType.Private]: () => [BattleListType.Private]: () =>
this.request(Queries.PrivateBattleHistoriesQuery) this.request(Queries.PrivateBattleHistoriesQuery)
.then((r) => getIdsFromGroups(r.privateBattleHistories)), .then((r) => getIdsFromGroups(r.privateBattleHistories)),
@ -168,6 +174,30 @@ export class Splatnet3 {
return await this.BATTLE_LIST_TYPE_MAP[battleListType](); return await this.BATTLE_LIST_TYPE_MAP[battleListType]();
} }
// Get all id from all battle list, sort by time, [0] is the latest
async getAllBattleList() {
const ALL_TYPE: BattleListType[] = [
BattleListType.Regular,
BattleListType.Bankara,
BattleListType.XBattle,
BattleListType.Event,
BattleListType.Private,
];
const ids: string[] = [];
for (const type of ALL_TYPE) {
ids.push(...await this.getBattleList(type));
}
// battleTime()
const timeMap = new Map<string, Date>(
ids.map((id) => [id, battleTime(id)] as const),
);
return ids.sort((a, b) =>
timeMap.get(b)!.getTime() - timeMap.get(a)!.getTime()
);
}
getBattleDetail( getBattleDetail(
id: string, id: string,
) { ) {

View File

@ -607,10 +607,14 @@ export enum BattleListType {
Latest, Latest,
Regular, Regular,
Bankara, Bankara,
Event,
XBattle,
Private, Private,
Coop, Coop,
} }
export type ListMethod = "latest" | "all";
export type StatInkUuidList = { export type StatInkUuidList = {
status: number; status: number;
code: number; code: number;

View File

@ -188,3 +188,14 @@ export function urlSimplify(url: string): { pathname: string } | string {
return url; return url;
} }
} }
export const battleTime = (id: string) => {
const { timestamp } = parseHistoryDetailId(id);
const dateStr = timestamp.replace(
/(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})(\d{2})/,
"$1-$2-$3T$4:$5:$6Z",
);
return new Date(dateStr);
};