aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2021-03-01 15:05:32 -0600
committermat <27899617+mat-1@users.noreply.github.com>2021-03-01 15:05:32 -0600
commitd00f71b611fd26216bf379df265e53493a1adcb3 (patch)
tree9616b70cda744b0057c3952ba4903e6c292eeb8b
parent03ab14d4ca9028c99f8d778d4266a2a1efb6d798 (diff)
downloadskyblock-api-d00f71b611fd26216bf379df265e53493a1adcb3.tar.gz
skyblock-api-d00f71b611fd26216bf379df265e53493a1adcb3.tar.bz2
skyblock-api-d00f71b611fd26216bf379df265e53493a1adcb3.zip
fix error on timedeo's profile
-rw-r--r--src/hypixelCached.ts12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/hypixelCached.ts b/src/hypixelCached.ts
index b407a69..4063069 100644
--- a/src/hypixelCached.ts
+++ b/src/hypixelCached.ts
@@ -52,7 +52,7 @@ function waitForSet(cache: NodeCache, key?: string, value?: string): Promise<any
const listener = (setKey, setValue) => {
if (setKey === key || (value && setValue === value)) {
cache.removeListener('set', listener)
- return resolve({ key, value })
+ return resolve({ key: setKey, value: setValue })
}
}
cache.on('set', listener)
@@ -73,7 +73,9 @@ export async function uuidFromUser(user: string): Promise<string> {
const username: any = usernameCache.get(undashUuid(user))
// if it has .then, then that means its a waitForSet promise. This is done to prevent requests made while it is already requesting
if (username.then) {
- return (await username).key
+ const { key: uuid, value: _username } = await username
+ usernameCache.set(uuid, _username)
+ return uuid
} else
return undashUuid(user)
}
@@ -92,7 +94,10 @@ export async function uuidFromUser(user: string): Promise<string> {
// not cached, actually fetch mojang api now
let { uuid, username } = await mojang.mojangDataFromUser(user)
- if (!uuid) return
+ if (!uuid) {
+ usernameCache.set(uuid, null)
+ return
+ }
// remove dashes from the uuid so its more normal
uuid = undashUuid(uuid)
@@ -133,6 +138,7 @@ export async function fetchPlayer(user: string): Promise<CleanPlayer> {
path: 'player',
args: { uuid: playerUuid }
})
+
if (!cleanPlayer) return
// clone in case it gets modified somehow later