Download battle details from regular/anarchy/private specific results

This commit is contained in:
Samuel Elliott 2022-10-26 14:30:01 +01:00
parent 8f6ae71061
commit 462ec96fe2
No known key found for this signature in database
GPG Key ID: 8420C7CDE43DC4D6

View File

@ -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);