aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2021-06-01 19:41:18 -0500
committermat <github@matdoes.dev>2021-06-01 19:41:18 -0500
commitb14a077a9bc35384d7561fd1b39bdad389cc4a53 (patch)
tree60932357984618c0b815dfa6b8eee7c10bc2fcd8 /src
parent58cf3377dfcb47d58e2ef936dcbbfa99c37783c4 (diff)
downloadskyblock-api-b14a077a9bc35384d7561fd1b39bdad389cc4a53.tar.gz
skyblock-api-b14a077a9bc35384d7561fd1b39bdad389cc4a53.tar.bz2
skyblock-api-b14a077a9bc35384d7561fd1b39bdad389cc4a53.zip
add key usage info to index
Diffstat (limited to 'src')
-rw-r--r--src/hypixelApi.ts15
-rw-r--r--src/index.ts2
2 files changed, 16 insertions, 1 deletions
diff --git a/src/hypixelApi.ts b/src/hypixelApi.ts
index 72af1af..a212f34 100644
--- a/src/hypixelApi.ts
+++ b/src/hypixelApi.ts
@@ -36,7 +36,7 @@ export function chooseApiKey(): string {
// find the api key with the lowest amount of uses
let bestKeyUsage: KeyUsage = null
let bestKey: string = null
- for (var key of shuffle(apiKeys)) {
+ for (let key of shuffle(apiKeys)) {
const keyUsage = apiKeyUsage[key]
// if the key has never been used before, use it
@@ -55,6 +55,19 @@ export function chooseApiKey(): string {
return bestKey
}
+export function getKeyUsage() {
+ let keyLimit = 0
+ let keyUsage = 0
+ for (let key of Object.values(apiKeyUsage)) {
+ keyLimit += key.limit
+ keyUsage += key.limit - key.remaining
+ }
+ return {
+ limit: keyLimit,
+ usage: keyUsage
+ }
+}
+
export interface HypixelResponse {
[key: string]: any | {
success: boolean
diff --git a/src/index.ts b/src/index.ts
index a4f9a39..0a27e4f 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -4,6 +4,7 @@ import rateLimit from 'express-rate-limit'
import * as constants from './constants'
import * as discord from './discord'
import express from 'express'
+import { getKeyUsage } from './hypixelApi'
const app = express()
@@ -39,6 +40,7 @@ app.get('/', async(req, res) => {
finishedCachingRawLeaderboards,
leaderboardUpdateMemberQueueSize: leaderboardUpdateMemberQueue.size,
leaderboardUpdateProfileQueueSize: leaderboardUpdateProfileQueue.size,
+ key: getKeyUsage()
})
})