1
0
mirror of https://github.com/zedeus/nitter synced 2024-11-25 11:09:32 +01:00

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

@ -9,7 +9,7 @@ import jester
import types, config, prefs, formatters, redis_cache, http_pool, tokens
import views/[general, about]
import routes/[
preferences, timeline, status, media, search, rss, list,
preferences, timeline, status, media, search, rss, list, debug,
unsupported, embed, resolver, router_utils]
const instancesUrl = "https://github.com/zedeus/nitter/wiki/Instances"
@ -49,6 +49,7 @@ createSearchRouter(cfg)
createMediaRouter(cfg)
createEmbedRouter(cfg)
createRssRouter(cfg)
createDebugRouter(cfg)
settings:
port = Port(cfg.port)
@ -98,3 +99,4 @@ routes:
extend status, ""
extend media, ""
extend embed, ""
extend debug, ""

View File

@ -42,3 +42,6 @@ template getCursor*(req: Request): string =
proc getNames*(name: string): seq[string] =
name.strip(chars={'/'}).split(",").filterIt(it.len > 0)
template respJson*(body: string) =
resp body, "application/json"

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")