Added steam id validator
This commit is contained in:
parent
6e9f319547
commit
f175fd8c98
47
pages/api/isvalidsteamid.js
Normal file
47
pages/api/isvalidsteamid.js
Normal file
@ -0,0 +1,47 @@
|
||||
import WebsiteTypes from "../../src/consts/WebsiteType";
|
||||
|
||||
const TO_CHECK = [
|
||||
WebsiteTypes.ScoreSaber.ApiUrl,
|
||||
WebsiteTypes.BeatLeader.ApiUrl,
|
||||
];
|
||||
|
||||
// TODO: Cache the result
|
||||
export default async function handler(req, res) {
|
||||
const steamId = req.query.steamid;
|
||||
if (!steamId) {
|
||||
return res.json({
|
||||
status: 404,
|
||||
message: "Steam id not provided: Provide in the query.",
|
||||
});
|
||||
}
|
||||
|
||||
let invalid = false;
|
||||
for (const url of TO_CHECK) {
|
||||
const isValid = await checkLeaderboard(url, steamId);
|
||||
|
||||
if (isValid) {
|
||||
break;
|
||||
}
|
||||
if (!isValid) {
|
||||
invalid = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return res.json({
|
||||
status: "OK",
|
||||
message: invalid ? `Invalid` : "Valid",
|
||||
});
|
||||
}
|
||||
|
||||
async function checkLeaderboard(url, steamId) {
|
||||
console.log(url.replace("%s", steamId));
|
||||
const data = await fetch(url.replace("%s", steamId), {
|
||||
headers: {
|
||||
"X-Requested-With": "BeatSaber Overlay",
|
||||
},
|
||||
});
|
||||
const json = await data.json();
|
||||
|
||||
return !!json.pp;
|
||||
}
|
Reference in New Issue
Block a user