mirror of
https://github.com/roleypoly/roleypoly.git
synced 2025-06-16 17:49:09 +00:00
feat(api): add rate-limiting and /clear-guild-cache (#198)
This commit is contained in:
parent
57d83699d5
commit
a4fd37d71c
7 changed files with 138 additions and 12 deletions
15
packages/api/utils/rate-limiting.ts
Normal file
15
packages/api/utils/rate-limiting.ts
Normal 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;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue