Add #isMojangBlocked

This commit is contained in:
Braydon 2024-04-14 15:56:45 -04:00
parent 499663aa64
commit 18293cc579

@ -55,3 +55,26 @@ export const getMinecraftServer = (
}
});
};
/**
* Check if the server with the
* given hostname is blocked by Mojang.
*
* @param hostname the server hostname to check
* @returns the promised blocked status
*/
export const isMojangBlocked = (hostname: string): Promise<boolean> => {
return new Promise(async (resolve, reject) => {
const response: Response = await fetch(
`${ENDPOINT}/server/blocked/${hostname}`
); // Request the server
const json: any = await response.json();
// Resolve the blocked status
if (response.ok) {
resolve(json.blocked as boolean);
} else {
reject(json as ErrorResponse); // The request failed
}
});
};