This repository has been archived on 2023-11-06. You can view files and clone it, but cannot push or open issues or pull requests.
beatsaber-overlay/src/helpers/validateSteamId.js
2022-10-20 18:00:27 +01:00

41 lines
873 B
JavaScript

import { default as LeaderboardType } from "../consts/LeaderboardType";
import RedisUtils from "../utils/redisUtils";
import Utils from "../utils/utils";
const KEY = "VALID_STEAM_ID_";
const TO_CHECK = [
LeaderboardType.ScoreSaber.ApiUrl.PlayerData,
LeaderboardType.BeatLeader.ApiUrl.PlayerData,
];
async function isValidSteamId(steamId) {
if (!steamId) {
return false;
}
if (steamId.length !== 17) {
return false;
}
const exists = await RedisUtils.exists(`${KEY}${steamId}`);
if (exists) {
const data = await RedisUtils.getValue(`${KEY}${steamId}`);
return Boolean(data);
}
let valid = false;
for (const url of TO_CHECK) {
const isValid = await Utils.checkLeaderboard(url, steamId);
if (isValid) {
valid = true;
break;
}
}
await RedisUtils.setValue(`${KEY}${steamId}`, valid);
return valid;
}
module.exports = {
isValidSteamId,
};