mirror of
https://github.com/zedeus/nitter
synced 2024-11-22 01:45:22 +01:00
Add more info to /.tokens endpoint
This commit is contained in:
parent
4d9fd1a6f8
commit
d4c6876bc9
10
src/routes/debug.nim
Normal file
10
src/routes/debug.nim
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
import jester
|
||||||
|
import router_utils
|
||||||
|
import ".."/[tokens, types]
|
||||||
|
|
||||||
|
proc createDebugRouter*(cfg: Config) =
|
||||||
|
router debug:
|
||||||
|
get "/.tokens":
|
||||||
|
cond cfg.enableDebug
|
||||||
|
respJson getPoolJson()
|
@ -1,5 +1,5 @@
|
|||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
import strutils, sequtils, uri, tables
|
import strutils, sequtils, uri, tables, json
|
||||||
from jester import Request, cookies
|
from jester import Request, cookies
|
||||||
|
|
||||||
import ../views/general
|
import ../views/general
|
||||||
@ -43,5 +43,5 @@ template getCursor*(req: Request): string =
|
|||||||
proc getNames*(name: string): seq[string] =
|
proc getNames*(name: string): seq[string] =
|
||||||
name.strip(chars={'/'}).split(",").filterIt(it.len > 0)
|
name.strip(chars={'/'}).split(",").filterIt(it.len > 0)
|
||||||
|
|
||||||
template respJson*(body: string) =
|
template respJson*(node: JsonNode) =
|
||||||
resp body, "application/json"
|
resp $node, "application/json"
|
||||||
|
@ -15,9 +15,15 @@ var
|
|||||||
tokenPool: seq[Token]
|
tokenPool: seq[Token]
|
||||||
lastFailed: Time
|
lastFailed: Time
|
||||||
|
|
||||||
proc getPoolJson*: string =
|
proc getPoolJson*(): JsonNode =
|
||||||
let list = newJObject()
|
var
|
||||||
|
list = newJObject()
|
||||||
|
totalReqs = 0
|
||||||
|
totalPending = 0
|
||||||
|
reqsPerApi: Table[string, int]
|
||||||
|
|
||||||
for token in tokenPool:
|
for token in tokenPool:
|
||||||
|
totalPending.inc(token.pending)
|
||||||
list[token.tok] = %*{
|
list[token.tok] = %*{
|
||||||
"apis": newJObject(),
|
"apis": newJObject(),
|
||||||
"pending": token.pending,
|
"pending": token.pending,
|
||||||
@ -27,7 +33,25 @@ proc getPoolJson*: string =
|
|||||||
|
|
||||||
for api in token.apis.keys:
|
for api in token.apis.keys:
|
||||||
list[token.tok]["apis"][$api] = %token.apis[api]
|
list[token.tok]["apis"][$api] = %token.apis[api]
|
||||||
return $list
|
|
||||||
|
let
|
||||||
|
maxReqs =
|
||||||
|
case api
|
||||||
|
of Api.listBySlug, Api.list: 500
|
||||||
|
of Api.timeline: 187
|
||||||
|
else: 180
|
||||||
|
reqs = maxReqs - token.apis[api].remaining
|
||||||
|
|
||||||
|
reqsPerApi[$api] = reqsPerApi.getOrDefault($api, 0) + reqs
|
||||||
|
totalReqs.inc(reqs)
|
||||||
|
|
||||||
|
return %*{
|
||||||
|
"amount": tokenPool.len,
|
||||||
|
"requests": totalReqs,
|
||||||
|
"pending": totalPending,
|
||||||
|
"apis": reqsPerApi,
|
||||||
|
"tokens": list
|
||||||
|
}
|
||||||
|
|
||||||
proc rateLimitError*(): ref RateLimitError =
|
proc rateLimitError*(): ref RateLimitError =
|
||||||
newException(RateLimitError, "rate limited")
|
newException(RateLimitError, "rate limited")
|
||||||
|
Loading…
Reference in New Issue
Block a user