mirror of
https://github.com/zedeus/nitter.git
synced 2024-12-12 02:56:29 +00:00
Use int for token reset instead of Time
This commit is contained in:
parent
34964f9e56
commit
4d9fd1a6f8
2 changed files with 3 additions and 9 deletions
|
@ -26,11 +26,7 @@ proc getPoolJson*: string =
|
|||
}
|
||||
|
||||
for api in token.apis.keys:
|
||||
list[token.tok]["apis"][$api] = %*{
|
||||
"remaining": token.apis[api].remaining,
|
||||
"reset": $token.apis[api].reset
|
||||
}
|
||||
|
||||
list[token.tok]["apis"][$api] = %token.apis[api]
|
||||
return $list
|
||||
|
||||
proc rateLimitError*(): ref RateLimitError =
|
||||
|
@ -71,7 +67,7 @@ proc isLimited(token: Token; api: Api): bool =
|
|||
|
||||
if api in token.apis:
|
||||
let limit = token.apis[api]
|
||||
return (limit.remaining <= 10 and limit.reset > getTime())
|
||||
return (limit.remaining <= 10 and limit.reset > epochTime().int)
|
||||
else:
|
||||
return false
|
||||
|
||||
|
@ -104,8 +100,6 @@ proc getToken*(api: Api): Future[Token] {.async.} =
|
|||
raise rateLimitError()
|
||||
|
||||
proc setRateLimit*(token: Token; api: Api; remaining, reset: int) =
|
||||
let reset = fromUnix(reset)
|
||||
|
||||
# avoid undefined behavior in race conditions
|
||||
if api in token.apis:
|
||||
let limit = token.apis[api]
|
||||
|
|
|
@ -20,7 +20,7 @@ type
|
|||
|
||||
RateLimit* = object
|
||||
remaining*: int
|
||||
reset*: Time
|
||||
reset*: int
|
||||
|
||||
Token* = ref object
|
||||
tok*: string
|
||||
|
|
Loading…
Reference in a new issue