feat(api): add rate-limiting and /clear-guild-cache (#198)

This commit is contained in:
41666 2021-03-23 22:14:33 -04:00 committed by GitHub
parent 57d83699d5
commit a4fd37d71c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 138 additions and 12 deletions

View file

@ -0,0 +1,15 @@
import { WrappedKVNamespace } from './kv';
export const useRateLimiter = (
kv: WrappedKVNamespace,
key: string,
timeoutSeconds: number
) => async (): Promise<boolean> => {
const value = await kv.get<boolean>(key);
if (value) {
return true;
}
await kv.put(key, true, timeoutSeconds);
return false;
};