mirror of
https://github.com/samuelthomas2774/nxapi.git
synced 2026-04-21 22:47:46 -05:00
Include summaries when downloading SplatNet 3 results
This commit is contained in:
parent
04e6a80496
commit
1e6cec9303
|
|
@ -2,11 +2,13 @@ import * as path from 'node:path';
|
|||
import * as fs from 'node:fs/promises';
|
||||
import createDebug from 'debug';
|
||||
import mkdirp from 'mkdirp';
|
||||
import { RequestId } from 'splatnet3-types/splatnet3';
|
||||
import type { Arguments as ParentArguments } from '../splatnet3.js';
|
||||
import { ArgumentsCamelCase, Argv, YargsArguments } from '../../util/yargs.js';
|
||||
import { initStorage } from '../../util/storage.js';
|
||||
import { getBulletToken } from '../../common/auth/splatnet3.js';
|
||||
import SplatNet3Api from '../../api/splatnet3.js';
|
||||
import { ResponseSymbol } from '../../api/util.js';
|
||||
|
||||
const debug = createDebug('cli:splatnet3:dump-results');
|
||||
|
||||
|
|
@ -26,11 +28,9 @@ export function builder(yargs: Argv<ParentArguments>) {
|
|||
}).option('battles', {
|
||||
describe: 'Include regular/ranked/private/festival battle results',
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
}).option('coop', {
|
||||
describe: 'Include coop (Salmon Run) results',
|
||||
type: 'boolean',
|
||||
default: true,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -48,10 +48,12 @@ export async function handler(argv: ArgumentsCamelCase<Arguments>) {
|
|||
|
||||
await mkdirp(directory);
|
||||
|
||||
if (argv.battles) {
|
||||
const _default = typeof argv.battles !== 'boolean' && typeof argv.coop !== 'boolean';
|
||||
|
||||
if (argv.battles ?? _default) {
|
||||
await dumpResults(splatnet, directory);
|
||||
}
|
||||
if (argv.coop) {
|
||||
if (argv.coop ?? _default) {
|
||||
await dumpCoopResults(splatnet, directory);
|
||||
}
|
||||
}
|
||||
|
|
@ -60,11 +62,49 @@ export async function dumpResults(
|
|||
splatnet: SplatNet3Api, directory: string
|
||||
) {
|
||||
debug('Fetching battle results');
|
||||
const player = await splatnet.getBattleHistoryCurrentPlayer();
|
||||
const battles = await splatnet.getLatestBattleHistories();
|
||||
const battles_regular = await splatnet.getRegularBattleHistories();
|
||||
const battles_anarchy = await splatnet.getBankaraBattleHistories();
|
||||
const battles_private = await splatnet.getPrivateBattleHistories();
|
||||
console.warn('Fetching battle results');
|
||||
|
||||
const [player, battles, battles_regular, battles_anarchy, battles_private] = await Promise.all([
|
||||
splatnet.getBattleHistoryCurrentPlayer(),
|
||||
splatnet.getLatestBattleHistories(),
|
||||
splatnet.getRegularBattleHistories(),
|
||||
splatnet.getBankaraBattleHistories(),
|
||||
splatnet.getPrivateBattleHistories(),
|
||||
]);
|
||||
|
||||
const filename = 'splatnet3-results-summary-' + Date.now() + '.json';
|
||||
const file = path.join(directory, filename);
|
||||
|
||||
debug('Writing %s', filename);
|
||||
await fs.writeFile(file, JSON.stringify({
|
||||
player: {
|
||||
result: player.data.currentPlayer,
|
||||
query: RequestId.BattleHistoryCurrentPlayerQuery,
|
||||
be_version: player[ResponseSymbol].headers.get('x-be-version'),
|
||||
},
|
||||
latestBattleHistories: {
|
||||
result: battles.data.latestBattleHistories,
|
||||
fest: battles.data.currentFest,
|
||||
query: RequestId.LatestBattleHistoriesQuery,
|
||||
be_version: battles[ResponseSymbol].headers.get('x-be-version'),
|
||||
},
|
||||
regularBattleHistories: {
|
||||
result: battles_regular.data.regularBattleHistories,
|
||||
query: RequestId.RegularBattleHistoriesQuery,
|
||||
be_version: battles_regular[ResponseSymbol].headers.get('x-be-version'),
|
||||
},
|
||||
bankaraBattleHistories: {
|
||||
result: battles_anarchy.data.bankaraBattleHistories,
|
||||
query: RequestId.BankaraBattleHistoriesQuery,
|
||||
be_version: battles_anarchy[ResponseSymbol].headers.get('x-be-version'),
|
||||
},
|
||||
privateBattleHistories: {
|
||||
result: battles_private.data.privateBattleHistories,
|
||||
query: RequestId.PrivateBattleHistoriesQuery,
|
||||
be_version: battles_private[ResponseSymbol].headers.get('x-be-version'),
|
||||
},
|
||||
app_version: splatnet.version,
|
||||
}, null, 4) + '\n', 'utf-8');
|
||||
|
||||
const skipped = [];
|
||||
|
||||
|
|
@ -72,21 +112,27 @@ export async function dumpResults(
|
|||
for (const group of battles.data.latestBattleHistories.historyGroups.nodes.reverse()) {
|
||||
for (const item of group.historyDetails.nodes.reverse()) {
|
||||
const id_str = Buffer.from(item.id, 'base64').toString() || item.id;
|
||||
const match = id_str.match(/^VsHistoryDetail-(u-[0-9a-z]{20}):([A-Z]+):((\d{8,}T\d{6})_([0-9a-f-]{36}))$/);
|
||||
const id = match ? match[1] + '-' + match[3] : id_str;
|
||||
|
||||
const filename = 'splatnet3-result-' + id_str + '.json';
|
||||
const filename = 'splatnet3-result-' + id + '-' + RequestId.VsHistoryDetailQuery + '.json';
|
||||
const file = path.join(directory, filename);
|
||||
|
||||
try {
|
||||
await fs.stat(file);
|
||||
skipped.push(item.id);
|
||||
} catch (err) {
|
||||
debug('Fetching battle result %s', id_str);
|
||||
debug('Fetching battle result %s', id);
|
||||
console.warn('Fetching battle result %s', id);
|
||||
const result = await splatnet.getBattleHistoryDetail(item.id);
|
||||
const pager = await splatnet.getBattleHistoryDetailPagerRefetch(item.id);
|
||||
|
||||
debug('Writing %s', filename);
|
||||
await fs.writeFile(file, JSON.stringify({
|
||||
result: result.data.vsHistoryDetail,
|
||||
query: RequestId.VsHistoryDetailQuery,
|
||||
app_version: splatnet.version,
|
||||
be_version: result[ResponseSymbol].headers.get('x-be-version'),
|
||||
}, null, 4) + '\n', 'utf-8');
|
||||
}
|
||||
}
|
||||
|
|
@ -100,28 +146,46 @@ export async function dumpResults(
|
|||
|
||||
export async function dumpCoopResults(splatnet: SplatNet3Api, directory: string) {
|
||||
debug('Fetching coop results');
|
||||
console.warn('Fetching coop results');
|
||||
const results = await splatnet.getCoopHistory();
|
||||
|
||||
const filename = 'splatnet3-coop-summary-' + Date.now() + '.json';
|
||||
const file = path.join(directory, filename);
|
||||
|
||||
debug('Writing %s', filename);
|
||||
await fs.writeFile(file, JSON.stringify({
|
||||
result: results.data.coopResult,
|
||||
query: RequestId.CoopHistoryQuery,
|
||||
app_version: splatnet.version,
|
||||
be_version: results[ResponseSymbol].headers.get('x-be-version'),
|
||||
}, null, 4) + '\n', 'utf-8');
|
||||
|
||||
const skipped = [];
|
||||
|
||||
// Reverse coop history order so oldest records are downloaded first
|
||||
for (const group of results.data.coopResult.historyGroups.nodes.reverse()) {
|
||||
for (const item of group.historyDetails.nodes.reverse()) {
|
||||
const id_str = Buffer.from(item.id, 'base64').toString() || item.id;
|
||||
const match = id_str.match(/^CoopHistoryDetail-(u-[0-9a-z]{20}):((\d{8,}T\d{6})_([0-9a-f-]{36}))$/);
|
||||
const id = match ? match[1] + '-' + match[2] : id_str;
|
||||
|
||||
const filename = 'splatnet3-coop-result-' + id_str + '.json';
|
||||
const filename = 'splatnet3-coop-result-' + id + '-' + RequestId.CoopHistoryDetailQuery + '.json';
|
||||
const file = path.join(directory, filename);
|
||||
|
||||
try {
|
||||
await fs.stat(file);
|
||||
skipped.push(item.id);
|
||||
} catch (err) {
|
||||
debug('Fetching co-op history %s', id_str);
|
||||
debug('Fetching co-op history %s', id);
|
||||
console.warn('Fetching co-op history %s', id);
|
||||
const result = await splatnet.getCoopHistoryDetail(item.id);
|
||||
|
||||
debug('Writing %s', filename);
|
||||
await fs.writeFile(file, JSON.stringify({
|
||||
result: result.data.coopHistoryDetail,
|
||||
query: RequestId.CoopHistoryDetailQuery,
|
||||
app_version: splatnet.version,
|
||||
be_version: result[ResponseSymbol].headers.get('x-be-version'),
|
||||
}, null, 4) + '\n', 'utf-8');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user