mirror of
https://github.com/misenhower/splatoon3.ink.git
synced 2026-04-24 06:46:52 -05:00
Clean up the way we detect whether an update is needed
This commit is contained in:
parent
cda854de0b
commit
46fdbbe8c7
|
|
@ -9,3 +9,14 @@ export async function exists(file) {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Determine whether a file is older than a given cutoff date (or doesn't exist)
|
||||
export async function olderThan(file, cutoff) {
|
||||
try {
|
||||
let stat = await fs.stat(file);
|
||||
|
||||
return stat.mtime < cutoff;
|
||||
} catch (e) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
import fs from 'fs/promises';
|
||||
import prefixedConsole from "../../common/prefixedConsole.mjs";
|
||||
import DataUpdater from "./DataUpdater.mjs";
|
||||
import { getFestId, getFestTeamId } from '../../common/util.mjs';
|
||||
import { exists } from '../../common/fs.mjs';
|
||||
import { olderThan } from '../../common/fs.mjs';
|
||||
|
||||
export default class FestivalRankingUpdater extends DataUpdater
|
||||
{
|
||||
|
|
@ -32,21 +31,13 @@ export default class FestivalRankingUpdater extends DataUpdater
|
|||
return this._console;
|
||||
}
|
||||
|
||||
async shouldUpdate() {
|
||||
// If the file doesn't exist, we need to download the data
|
||||
if (!(await exists(this.getPath(this.filename)))) {
|
||||
return true;
|
||||
}
|
||||
|
||||
shouldUpdate() {
|
||||
// How long until this festival ends/ended?
|
||||
// We want to update this data until 4 hours after the Splatfest ends
|
||||
let diff = Date.now() - new Date(this.endTime);
|
||||
if (diff < 4 * 60 * 60 * 1000) {
|
||||
return true;
|
||||
}
|
||||
let cutoff = new Date(this.endTime);
|
||||
cutoff.setHours(cutoff.getHours() + 4);
|
||||
|
||||
// Otherwise, no need to update
|
||||
return false;
|
||||
return olderThan(this.getPath(this.filename), cutoff);
|
||||
}
|
||||
|
||||
async getData(locale) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user