mirror of
https://github.com/mfts/papermark.git
synced 2025-12-20 01:03:24 +08:00
31 lines
826 B
TypeScript
31 lines
826 B
TypeScript
import { Ratelimit } from "@upstash/ratelimit";
|
|
import { Redis } from "@upstash/redis";
|
|
|
|
export const redis = new Redis({
|
|
url: process.env.UPSTASH_REDIS_REST_URL as string,
|
|
token: process.env.UPSTASH_REDIS_REST_TOKEN as string,
|
|
});
|
|
|
|
export const lockerRedisClient = new Redis({
|
|
url: process.env.UPSTASH_REDIS_REST_LOCKER_URL as string,
|
|
token: process.env.UPSTASH_REDIS_REST_LOCKER_TOKEN as string,
|
|
});
|
|
|
|
// Create a new ratelimiter, that allows 10 requests per 10 seconds by default
|
|
export const ratelimit = (
|
|
requests: number = 10,
|
|
seconds:
|
|
| `${number} ms`
|
|
| `${number} s`
|
|
| `${number} m`
|
|
| `${number} h`
|
|
| `${number} d` = "10 s",
|
|
) => {
|
|
return new Ratelimit({
|
|
redis: redis,
|
|
limiter: Ratelimit.slidingWindow(requests, seconds),
|
|
analytics: true,
|
|
prefix: "papermark",
|
|
});
|
|
};
|