From 462ec96fe2c7396c996ef3f90b8025d428dbd0eb Mon Sep 17 00:00:00 2001 From: Samuel Elliott Date: Wed, 26 Oct 2022 14:30:01 +0100 Subject: [PATCH] Download battle details from regular/anarchy/private specific results --- src/cli/splatnet3/dump-results.ts | 40 +++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/cli/splatnet3/dump-results.ts b/src/cli/splatnet3/dump-results.ts index 2b5f6d9..f5c98be 100644 --- a/src/cli/splatnet3/dump-results.ts +++ b/src/cli/splatnet3/dump-results.ts @@ -137,6 +137,7 @@ export async function dumpResults( }, null, 4) + '\n', 'utf-8'); const downloaded = []; + const latest_unique_ids = []; const skipped = []; // Reverse battle history order so oldest records are downloaded first @@ -146,6 +147,45 @@ export async function dumpResults( 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; + latest_unique_ids.push(id); + + 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); + 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'); + + downloaded.push(item.id); + } + } + } + + for (const group of [ + ...battles_regular.data.regularBattleHistories.historyGroups.nodes, + ...battles_anarchy.data.bankaraBattleHistories.historyGroups.nodes, + ...battles_private.data.privateBattleHistories.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; + + if (latest_unique_ids.includes(id)) continue; + const filename = 'splatnet3-result-' + id + '-' + RequestId.VsHistoryDetailQuery + '.json'; const file = path.join(directory, filename);