feat: add fetch from all modes
parent
8a96cb321c
commit
91f528a3be
3
s3si.ts
3
s3si.ts
|
|
@ -32,8 +32,7 @@ Options:
|
|||
(e.g. "stat.ink,file")
|
||||
--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 "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.
|
||||
"auto" is the default setting.
|
||||
"latest" is the default setting.
|
||||
--no-progress, -n Disable progress bar
|
||||
--monitor, -m Monitor mode
|
||||
--skip-mode <mode>, -s Skip mode (default: null)
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import {
|
|||
HistoryGroups,
|
||||
RankParam,
|
||||
} from "./types.ts";
|
||||
import { gameId, parseHistoryDetailId } from "./utils.ts";
|
||||
import { battleTime, gameId } from "./utils.ts";
|
||||
import { getSeason } from "./VersionData.ts";
|
||||
|
||||
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 = {
|
||||
id: string;
|
||||
gameId: string;
|
||||
|
|
|
|||
11
src/app.ts
11
src/app.ts
|
|
@ -10,8 +10,6 @@ import { delay, showError } from "./utils.ts";
|
|||
import { GameFetcher } from "./GameFetcher.ts";
|
||||
import { DEFAULT_ENV, Env } from "./env.ts";
|
||||
|
||||
export type ListMethod = "latest" | "all" | "auto";
|
||||
|
||||
export type Opts = {
|
||||
profilePath: string;
|
||||
exporter: string;
|
||||
|
|
@ -31,7 +29,7 @@ export const DEFAULT_OPTS: Opts = {
|
|||
noProgress: false,
|
||||
monitor: false,
|
||||
withSummary: false,
|
||||
listMethod: "auto",
|
||||
listMethod: "latest",
|
||||
env: DEFAULT_ENV,
|
||||
};
|
||||
|
||||
|
|
@ -167,7 +165,12 @@ export class App {
|
|||
this.env.logger.log("Skip exporting VS games.");
|
||||
} else {
|
||||
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 fetcher = new GameFetcher({
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ import {
|
|||
} from "./types.ts";
|
||||
import { DEFAULT_ENV, Env } from "./env.ts";
|
||||
import { getBulletToken, getGToken } from "./iksm.ts";
|
||||
import { parseHistoryDetailId } from "./utils.ts";
|
||||
import { battleTime, parseHistoryDetailId } from "./utils.ts";
|
||||
|
||||
export class Splatnet3 {
|
||||
protected profile: Profile;
|
||||
|
|
@ -137,6 +137,12 @@ export class Splatnet3 {
|
|||
[BattleListType.Bankara]: () =>
|
||||
this.request(Queries.BankaraBattleHistoriesQuery)
|
||||
.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]: () =>
|
||||
this.request(Queries.PrivateBattleHistoriesQuery)
|
||||
.then((r) => getIdsFromGroups(r.privateBattleHistories)),
|
||||
|
|
@ -168,6 +174,30 @@ export class Splatnet3 {
|
|||
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(
|
||||
id: string,
|
||||
) {
|
||||
|
|
|
|||
|
|
@ -607,10 +607,14 @@ export enum BattleListType {
|
|||
Latest,
|
||||
Regular,
|
||||
Bankara,
|
||||
Event,
|
||||
XBattle,
|
||||
Private,
|
||||
Coop,
|
||||
}
|
||||
|
||||
export type ListMethod = "latest" | "all";
|
||||
|
||||
export type StatInkUuidList = {
|
||||
status: number;
|
||||
code: number;
|
||||
|
|
|
|||
11
src/utils.ts
11
src/utils.ts
|
|
@ -188,3 +188,14 @@ export function urlSimplify(url: string): { pathname: string } | string {
|
|||
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);
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue