This commit is contained in:
1 parent
9ca9625b50
commit
c71726af51
2 files changed
+21
-8
No files matched your search
+3
-1
@@ -53,7 +53,9 @@ export default defineConfig({
|
|||||||
DATABASE_URI: envField.string({ context: 'server', access: 'secret' }),
|
DATABASE_URI: envField.string({ context: 'server', access: 'secret' }),
|
||||||
|
|
||||||
BASE_HOST: envField.string({ context: 'server', access: 'secret', default: 'http://localhost:4321' }),
|
BASE_HOST: envField.string({ context: 'server', access: 'secret', default: 'http://localhost:4321' }),
|
||||||
BASE_PATH: envField.string({ context: 'server', access: 'secret', default: '/' })
|
BASE_PATH: envField.string({ context: 'server', access: 'secret', default: '/' }),
|
||||||
|
|
||||||
|
OPENXBL_API_KEY: envField.string({ context: 'server', access: 'secret', optional: true })
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
+18
-7
@@ -1,3 +1,5 @@
|
|||||||
|
import { OPENXBL_API_KEY } from "astro:env/server";
|
||||||
|
|
||||||
export async function getJavaUuid(username: string) {
|
export async function getJavaUuid(username: string) {
|
||||||
const response = await fetch(`https://api.mojang.com/users/profiles/minecraft/${username}`);
|
const response = await fetch(`https://api.mojang.com/users/profiles/minecraft/${username}`);
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
@@ -14,15 +16,24 @@ export async function getJavaUuid(username: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function getBedrockUuid(username: string): Promise<string | null> {
|
export async function getBedrockUuid(username: string): Promise<string | null> {
|
||||||
const response = await fetch(`https://api.geysermc.org/v2/xbox/xuid/${username}`);
|
if (!OPENXBL_API_KEY) throw new Error();
|
||||||
|
const response = await fetch(`https://api.xbl.io/v2/search/${username}`, {
|
||||||
|
headers: {
|
||||||
|
"X-Authorization": OPENXBL_API_KEY
|
||||||
|
}
|
||||||
|
});
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
// invalid gamertag, either empty or longer than 16 chars
|
// invalid api key
|
||||||
if (response.status == 400) throw new Error();
|
if (response.status == 401) throw new Error();
|
||||||
// account doesn't exist or the underlying xbox live api has issues
|
// rate limit
|
||||||
if (response.status == 503) throw new Error();
|
if (response.status == 429) throw new Error();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
const json = await response.json();
|
const json: { content: { people: Array<{ gamertag: string; xuid: string; }> } } = await response.json();
|
||||||
const xuid: string = (json['xuid'] as number).toString(16);
|
|
||||||
|
const xuidPerson = json.content.people.find((v) => v.gamertag.toLowerCase() == username.toLowerCase());
|
||||||
|
if (!xuidPerson) throw new Error();
|
||||||
|
const xuid = parseInt(xuidPerson.xuid).toString(16);
|
||||||
|
|
||||||
return `00000000-0000-0000-${xuid.substring(0, 4)}-${xuid.substring(4)}`;
|
return `00000000-0000-0000-${xuid.substring(0, 4)}-${xuid.substring(4)}`;
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user