Add cache to steam id validator

This commit is contained in:
Liam 2022-10-19 17:31:32 +01:00
parent 8b846ed681
commit 1ec8577d63
2 changed files with 12 additions and 0 deletions

@ -1,3 +1,4 @@
import SteamIdCache from "../../src/caches/SteamIdCache";
import WebsiteTypes from "../../src/consts/WebsiteType";
const TO_CHECK = [
@ -15,6 +16,13 @@ export default async function handler(req, res) {
});
}
if (SteamIdCache.has(steamId)) {
return res.json({
status: "OK",
message: SteamIdCache.get(steamId) ? `Invalid` : "Valid",
});
}
let invalid = false;
for (const url of TO_CHECK) {
const isValid = await checkLeaderboard(url, steamId);
@ -28,6 +36,7 @@ export default async function handler(req, res) {
}
}
SteamIdCache.set(steamId, invalid);
return res.json({
status: "OK",
message: invalid ? `Invalid` : "Valid",

@ -0,0 +1,3 @@
const CACHE = new Map();
module.exports = CACHE;