This commit is contained in:
14
src/util/minecraft.ts
Normal file
14
src/util/minecraft.ts
Normal file
@ -0,0 +1,14 @@
|
||||
export async function getJavaUuid(username: string) {
|
||||
const response = await fetch(`https://api.mojang.com/users/profiles/minecraft/${username}`);
|
||||
if (!response.ok) {
|
||||
// rate limit
|
||||
if (response.status == 429) return null;
|
||||
// user doesn't exist
|
||||
else if (response.status < 500) throw new Error();
|
||||
return null;
|
||||
}
|
||||
const json = await response.json();
|
||||
const id: string = json['id'];
|
||||
// prettier-ignore
|
||||
return `${id.substring(0, 8)}-${id.substring(8, 12)}-${id.substring(12, 16)}-${id.substring(16, 20)}-${id.substring(20)}`;
|
||||
}
|
Reference in New Issue
Block a user