From 1ec8577d63aa8053908feca2238f8fd8a748d0ca Mon Sep 17 00:00:00 2001 From: Liam <67254223+RealFascinated@users.noreply.github.com> Date: Wed, 19 Oct 2022 17:31:32 +0100 Subject: [PATCH] Add cache to steam id validator --- pages/api/validateid.js | 9 +++++++++ src/caches/SteamIdCache.js | 3 +++ 2 files changed, 12 insertions(+) create mode 100644 src/caches/SteamIdCache.js 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;