mirror of
https://github.com/misenhower/splatoon3.ink.git
synced 2026-04-26 07:49:22 -05:00
This should reduce the number of queries needed during high-load times (like waiting for Splatfest results).
76 lines
1.8 KiB
JavaScript
76 lines
1.8 KiB
JavaScript
import jsonpath from 'jsonpath';
|
|
import prefixedConsole from "../../common/prefixedConsole.mjs";
|
|
import { getXRankSeasonId } from '../../common/util.mjs';
|
|
import DataUpdater from "./DataUpdater.mjs";
|
|
import XRankDetailUpdater from "./XRankDetailUpdater.mjs";
|
|
|
|
export default class XRankUpdater extends DataUpdater
|
|
{
|
|
name = 'X-Rank';
|
|
filename = 'xrank';
|
|
directory = 'xrank';
|
|
archiveOnePerHour = false;
|
|
|
|
imagePaths = [
|
|
'$..image.url',
|
|
'$..image2d.url',
|
|
'$..image2dThumbnail.url',
|
|
'$..image3d.url',
|
|
'$..image3dThumbnail.url',
|
|
];
|
|
|
|
constructor(divisionName, divisionKey) {
|
|
super();
|
|
|
|
this.divisionName = divisionName;
|
|
this.divisionKey = divisionKey;
|
|
this.filename += `.${divisionName.toLowerCase()}`;
|
|
}
|
|
|
|
get console() {
|
|
this._console ??= prefixedConsole('Updater', this.region, this.name, this.divisionName);
|
|
|
|
return this._console;
|
|
}
|
|
|
|
shouldUpdate() {
|
|
if (this.settings.disableXRank) {
|
|
this.console.log('X-Rank updates disabled');
|
|
|
|
return false;
|
|
}
|
|
|
|
return super.shouldUpdate();
|
|
}
|
|
|
|
async getData(locale) {
|
|
let result = await this.splatnet(locale).getXRankingData(this.divisionKey);
|
|
let seasons = this.getSeasons(result.data);
|
|
|
|
for (let season of seasons) {
|
|
this.deriveSeasonId(season);
|
|
await this.updateSeasonDetail(season);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
getSeasons(data) {
|
|
return [
|
|
data.xRanking.currentSeason,
|
|
...data.xRanking.pastSeasons.nodes,
|
|
];
|
|
}
|
|
|
|
deriveSeasonId(season) {
|
|
season.__splatoon3ink_id = getXRankSeasonId(season.id);
|
|
}
|
|
|
|
async updateSeasonDetail(season) {
|
|
for (let type of this.splatnet().getXRankingDetailQueryTypes()) {
|
|
let updater = new XRankDetailUpdater(season.id, season.endTime, type);
|
|
await updater.updateIfNeeded();
|
|
}
|
|
}
|
|
}
|