aboutsummaryrefslogtreecommitdiff
path: root/build
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2021-06-02 19:26:33 -0500
committermat <github@matdoes.dev>2021-06-02 19:26:33 -0500
commita43543190cccac676a0c38dd0a015bccf7b3e6c9 (patch)
tree1596f868d2af47772116eff1e2a7907a8df00687 /build
parent1894126287af5fc584a2b65b27604c776e0b24f2 (diff)
downloadskyblock-api-a43543190cccac676a0c38dd0a015bccf7b3e6c9.tar.gz
skyblock-api-a43543190cccac676a0c38dd0a015bccf7b3e6c9.tar.bz2
skyblock-api-a43543190cccac676a0c38dd0a015bccf7b3e6c9.zip
add api.ashcon.app as alternative to mojang api
Diffstat (limited to 'build')
-rw-r--r--build/mojang.js31
1 files changed, 28 insertions, 3 deletions
diff --git a/build/mojang.js b/build/mojang.js
index 9641422..aa60b57 100644
--- a/build/mojang.js
+++ b/build/mojang.js
@@ -6,7 +6,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
-exports.profileFromUser = exports.profileFromUsername = exports.profileFromUuid = void 0;
+exports.profileFromUser = exports.profileFromUsernameAlternative = exports.profileFromUsername = exports.profileFromUuid = void 0;
const node_fetch_1 = __importDefault(require("node-fetch"));
const https_1 = require("https");
const util_1 = require("./util");
@@ -58,8 +58,10 @@ async function profileFromUsername(username) {
try {
data = await fetchResponse.json();
}
- catch {
- return { uuid: null, username: null };
+ catch { }
+ if (!data.id) {
+ console.log('mojang api failed, trying ashcon as backup');
+ return await profileFromUsernameAlternative(username);
}
return {
uuid: data.id,
@@ -67,6 +69,29 @@ async function profileFromUsername(username) {
};
}
exports.profileFromUsername = profileFromUsername;
+async function profileFromUsernameAlternative(username) {
+ let fetchResponse;
+ try {
+ fetchResponse = await node_fetch_1.default(`https://api.ashcon.app/mojang/v2/user/${username}`, { agent: () => httpsAgent });
+ }
+ catch {
+ // if there's an error, wait a second and try again
+ await new Promise((resolve) => setTimeout(resolve, 1000));
+ return await profileFromUsernameAlternative(username);
+ }
+ let data;
+ try {
+ data = await fetchResponse.json();
+ }
+ catch {
+ return { uuid: null, username: null };
+ }
+ return {
+ uuid: data.uuid,
+ username: data.username
+ };
+}
+exports.profileFromUsernameAlternative = profileFromUsernameAlternative;
async function profileFromUser(user) {
if (util_1.isUuid(user)) {
return await profileFromUuid(user);