Support running data updaters without all region tokens

This commit is contained in:
Samuel Elliott 2022-11-07 18:35:51 +00:00
parent 7689ef7bdc
commit 0e4812079f
No known key found for this signature in database
GPG Key ID: 8420C7CDE43DC4D6
4 changed files with 28 additions and 12 deletions

View File

@ -34,7 +34,7 @@ export default class ImageProcessor
}
publicUrl(file) {
return `${this.siteUrl}/${this.outputDirectory}/${file}`;
return `${this.siteUrl ?? ''}/${this.outputDirectory}/${file}`;
}
async exists(file) {

View File

@ -3,21 +3,24 @@ import StageScheduleUpdater from "./updaters/StageScheduleUpdater.mjs";
import CoopUpdater from "./updaters/CoopUpdater.mjs";
import FestivalUpdater from "./updaters/FestivalUpdater.mjs";
import CurrentFestivalUpdater from "./updaters/CurrentFestivalUpdater.mjs";
import { regionTokens } from "../splatnet/NsoClient.mjs";
function updaters() {
const tokens = regionTokens();
return [
new StageScheduleUpdater,
new GearUpdater,
new CoopUpdater,
new FestivalUpdater('US'),
new FestivalUpdater('EU'),
new FestivalUpdater('JP'),
new FestivalUpdater('AP'),
new CurrentFestivalUpdater('US'),
new CurrentFestivalUpdater('EU'),
new CurrentFestivalUpdater('JP'),
new CurrentFestivalUpdater('AP'),
];
tokens.US && new FestivalUpdater('US'),
tokens.EU && new FestivalUpdater('EU'),
tokens.JP && new FestivalUpdater('JP'),
tokens.AP && new FestivalUpdater('AP'),
tokens.US && new CurrentFestivalUpdater('US'),
tokens.EU && new CurrentFestivalUpdater('EU'),
tokens.JP && new CurrentFestivalUpdater('JP'),
tokens.AP && new CurrentFestivalUpdater('AP'),
].filter(u => u);
}
export async function updateAll() {

View File

@ -22,6 +22,14 @@ export function regionTokens() {
};
}
function getDefaultRegion() {
for (const [region, token] of Object.entries(regionTokens())) {
if (token) return region;
}
throw new Error('Session token not set for any region');
}
export default class NsoClient
{
constructor(region, nintendoToken) {
@ -33,7 +41,7 @@ export default class NsoClient
}
static make(region = null) {
region ??= 'US';
region ??= getDefaultRegion();
let tokens = regionTokens();
if (!Object.keys(tokens).includes(region)) {

View File

@ -10,7 +10,12 @@ import SplatNet3Client, { SPLATNET3_WEB_SERVICE_ID } from "./SplatNet3Client.mjs
export async function warmCaches() {
console.info('Warming caches...');
for (let region of Object.keys(regionTokens())) {
for (let [region, token] of Object.entries(regionTokens())) {
if (!token) {
console.warn('Session token not set for region %s', region);
continue;
}
await warmCache(region);
}
}