Use int for token reset instead of Time

This commit is contained in:
Zed 2022-01-06 00:19:09 +01:00
parent 34964f9e56
commit 4d9fd1a6f8
2 changed files with 3 additions and 9 deletions

View file

@ -26,11 +26,7 @@ proc getPoolJson*: string =
} }
for api in token.apis.keys: for api in token.apis.keys:
list[token.tok]["apis"][$api] = %*{ list[token.tok]["apis"][$api] = %token.apis[api]
"remaining": token.apis[api].remaining,
"reset": $token.apis[api].reset
}
return $list return $list
proc rateLimitError*(): ref RateLimitError = proc rateLimitError*(): ref RateLimitError =
@ -71,7 +67,7 @@ proc isLimited(token: Token; api: Api): bool =
if api in token.apis: if api in token.apis:
let limit = token.apis[api] let limit = token.apis[api]
return (limit.remaining <= 10 and limit.reset > getTime()) return (limit.remaining <= 10 and limit.reset > epochTime().int)
else: else:
return false return false
@ -104,8 +100,6 @@ proc getToken*(api: Api): Future[Token] {.async.} =
raise rateLimitError() raise rateLimitError()
proc setRateLimit*(token: Token; api: Api; remaining, reset: int) = proc setRateLimit*(token: Token; api: Api; remaining, reset: int) =
let reset = fromUnix(reset)
# avoid undefined behavior in race conditions # avoid undefined behavior in race conditions
if api in token.apis: if api in token.apis:
let limit = token.apis[api] let limit = token.apis[api]

View file

@ -20,7 +20,7 @@ type
RateLimit* = object RateLimit* = object
remaining*: int remaining*: int
reset*: Time reset*: int
Token* = ref object Token* = ref object
tok*: string tok*: string