feat: add rate limiting and more error handling to Cal.ai (#11898)
Co-authored-by: tedspare <[email protected]>
This commit is contained in:
1 parent
4b8bdeba74
commit
9e927af813
5 files changed
+49
-13
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import { TRPCError } from "@calcom/trpc";
|
||||
import { TRPCError } from "@calcom/trpc/server";
|
||||
|
||||
import type { RateLimitHelper } from "./rateLimit";
|
||||
import { rateLimiter } from "./rateLimit";
|
||||
|
||||
@@ -7,7 +7,7 @@ import logger from "./logger";
|
||||
const log = logger.getChildLogger({ prefix: ["RateLimit"] });
|
||||
|
||||
export type RateLimitHelper = {
|
||||
rateLimitingType?: "core" | "forcedSlowMode" | "common" | "api";
|
||||
rateLimitingType?: "core" | "forcedSlowMode" | "common" | "api" | "ai";
|
||||
identifier: string;
|
||||
};
|
||||
|
||||
@@ -75,6 +75,12 @@ export function rateLimiter() {
|
||||
prefix: "ratelimit:api",
|
||||
limiter: Ratelimit.fixedWindow(10, "60s"),
|
||||
}),
|
||||
ai: new Ratelimit({
|
||||
redis,
|
||||
analytics: true,
|
||||
prefix: "ratelimit",
|
||||
limiter: Ratelimit.fixedWindow(20, "1d"),
|
||||
}),
|
||||
};
|
||||
|
||||
async function rateLimit({ rateLimitingType = "core", identifier }: RateLimitHelper) {
|
||||
|
||||
Reference in new issue
Block a user