diff --git a/pages/api/validateid.js b/pages/api/validateid.js index f0c87c7..073e3e6 100644 --- a/pages/api/validateid.js +++ b/pages/api/validateid.js @@ -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", diff --git a/src/caches/SteamIdCache.js b/src/caches/SteamIdCache.js new file mode 100644 index 0000000..2934fa0 --- /dev/null +++ b/src/caches/SteamIdCache.js @@ -0,0 +1,3 @@ +const CACHE = new Map(); + +module.exports = CACHE;