aboutsummaryrefslogtreecommitdiff
path: root/src/hypixelApi.ts
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2021-06-29 17:54:50 -0500
committermat <github@matdoes.dev>2021-06-29 17:54:50 -0500
commit49ff24343e1c964b6cb82fdf76957ffd2f27d049 (patch)
tree820a3668e21dffc7eefa53630944412d9d97a129 /src/hypixelApi.ts
parent758ca15277daa11ce1ec86ce7f07ea7beee9eb8f (diff)
parentc0c534dafb54ebf9f95a5054f576ad99de29f232 (diff)
downloadskyblock-api-49ff24343e1c964b6cb82fdf76957ffd2f27d049.tar.gz
skyblock-api-49ff24343e1c964b6cb82fdf76957ffd2f27d049.tar.bz2
skyblock-api-49ff24343e1c964b6cb82fdf76957ffd2f27d049.zip
Merge branch 'main' of https://github.com/skyblockstats/skyblock-api into main
Diffstat (limited to 'src/hypixelApi.ts')
-rw-r--r--src/hypixelApi.ts12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/hypixelApi.ts b/src/hypixelApi.ts
index b3a1cae..1b57d8f 100644
--- a/src/hypixelApi.ts
+++ b/src/hypixelApi.ts
@@ -32,10 +32,10 @@ const baseHypixelAPI = 'https://api.hypixel.net'
/** Choose the best current API key */
-export function chooseApiKey(): string {
+export function chooseApiKey(): string | null {
// find the api key with the lowest amount of uses
- let bestKeyUsage: KeyUsage = null
- let bestKey: string = null
+ let bestKeyUsage: KeyUsage | null = null
+ let bestKey: string | null = null
for (let key of shuffle(apiKeys.slice())) {
const keyUsage = apiKeyUsage[key]
@@ -173,9 +173,9 @@ export async function sendApiRequest({ path, key, args }): Promise<HypixelRespon
if (fetchResponse.headers.get('ratelimit-limit'))
// remember how many uses it has
apiKeyUsage[key] = {
- remaining: parseInt(fetchResponse.headers.get('ratelimit-remaining')),
- limit: parseInt(fetchResponse.headers.get('ratelimit-limit')),
- reset: Date.now() + parseInt(fetchResponse.headers.get('ratelimit-reset')) * 1000
+ remaining: parseInt(fetchResponse.headers.get('ratelimit-remaining') ?? '0'),
+ limit: parseInt(fetchResponse.headers.get('ratelimit-limit') ?? '0'),
+ reset: Date.now() + parseInt(fetchResponse.headers.get('ratelimit-reset') ?? '0') * 1000
}
if (fetchJsonParsed.throttle) {