Add /.tokens debug endpoint to see token pool

This commit is contained in:
Zed
2022-01-05 22:49:16 +01:00
parent dd71e60f35
commit f9c9b0d3a4
3 changed files with 22 additions and 1 deletions

View File

@@ -14,6 +14,22 @@ var
tokenPool: seq[Token]
lastFailed: Time
proc getPoolJson*: string =
let list = newJObject()
for token in tokenPool:
list[token.tok] = %*{
"apis": newJObject(),
"init": $token.init,
"lastUse": $token.lastUse
}
for api in token.apis.keys:
list[token.tok]["apis"][$api] = %*{
"remaining": token.apis[api].remaining,
"reset": $token.apis[api].reset
}
return $list
proc rateLimitError*(): ref RateLimitError =
newException(RateLimitError, "rate limited")