mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-02 04:56:07 +00:00
18 lines
542 B
TypeScript
18 lines
542 B
TypeScript
import { RestManager } from "./restManager.ts";
|
|
|
|
/** Check the rate limits for a url or a bucket. */
|
|
export function checkRateLimits(rest: RestManager, url: string) {
|
|
const ratelimited = rest.rateLimitedPaths.get(url);
|
|
const global = rest.rateLimitedPaths.get("global");
|
|
const now = Date.now();
|
|
|
|
if (ratelimited && now < ratelimited.resetTimestamp) {
|
|
return ratelimited.resetTimestamp - now;
|
|
}
|
|
if (global && now < global.resetTimestamp) {
|
|
return global.resetTimestamp - now;
|
|
}
|
|
|
|
return false;
|
|
}
|