Skip to content

Commit

Permalink
fix(api): update username retrieval logic to improve cache handling
Browse files Browse the repository at this point in the history
  • Loading branch information
DarthGigi committed Dec 23, 2024
1 parent 76fd0d9 commit 1744784
Showing 1 changed file with 2 additions and 6 deletions.
8 changes: 2 additions & 6 deletions src/lib/server/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export async function getUsername(paramPlayer: string, options = { cache: false
}

const username = await REDIS.get(`USERNAME:${paramPlayer}`);
if (username || options.cache) {
if (username && options.cache) {
return username ?? paramPlayer;
}

Expand All @@ -99,11 +99,7 @@ export async function getUsername(paramPlayer: string, options = { cache: false
}

async function resolveUsernameOrUUID(paramPlayer: string) {
if (isUUID(paramPlayer)) {
return { uuid: paramPlayer };
}

const response = await fetch(`https://mowojang.matdoes.dev/users/profiles/minecraft/${paramPlayer}`);
const response = await fetch(`https://mowojang.matdoes.dev/${paramPlayer}`);
if (response.status === 204) {
throw new SkyCryptError("Player not found");
}
Expand Down

0 comments on commit 1744784

Please sign in to comment.