fix: ratelimit - updates (#10347)
parent
4f488be654
commit
8cdddfa1d0
|
@ -7,7 +7,7 @@ import logger from "./logger";
|
||||||
const log = logger.getChildLogger({ prefix: ["RateLimit"] });
|
const log = logger.getChildLogger({ prefix: ["RateLimit"] });
|
||||||
|
|
||||||
export type RateLimitHelper = {
|
export type RateLimitHelper = {
|
||||||
rateLimitingType?: "core" | "forcedSlowMode";
|
rateLimitingType?: "core" | "forcedSlowMode" | "common";
|
||||||
identifier: string;
|
identifier: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -57,6 +57,12 @@ export function rateLimiter() {
|
||||||
prefix: "ratelimit",
|
prefix: "ratelimit",
|
||||||
limiter: Ratelimit.fixedWindow(10, "60s"),
|
limiter: Ratelimit.fixedWindow(10, "60s"),
|
||||||
}),
|
}),
|
||||||
|
common: new Ratelimit({
|
||||||
|
redis,
|
||||||
|
analytics: true,
|
||||||
|
prefix: "ratelimit",
|
||||||
|
limiter: Ratelimit.fixedWindow(200, "60s"),
|
||||||
|
}),
|
||||||
forcedSlowMode: new Ratelimit({
|
forcedSlowMode: new Ratelimit({
|
||||||
redis,
|
redis,
|
||||||
analytics: true,
|
analytics: true,
|
||||||
|
|
|
@ -2,6 +2,7 @@ import { type PrismaClient, Prisma } from "@prisma/client";
|
||||||
import { orderBy } from "lodash";
|
import { orderBy } from "lodash";
|
||||||
|
|
||||||
import { hasFilter } from "@calcom/features/filters/lib/hasFilter";
|
import { hasFilter } from "@calcom/features/filters/lib/hasFilter";
|
||||||
|
import { checkRateLimitAndThrowError } from "@calcom/lib/checkRateLimitAndThrowError";
|
||||||
import { CAL_URL } from "@calcom/lib/constants";
|
import { CAL_URL } from "@calcom/lib/constants";
|
||||||
import { markdownToSafeHTML } from "@calcom/lib/markdownToSafeHTML";
|
import { markdownToSafeHTML } from "@calcom/lib/markdownToSafeHTML";
|
||||||
import { getBookerUrl } from "@calcom/lib/server/getBookerUrl";
|
import { getBookerUrl } from "@calcom/lib/server/getBookerUrl";
|
||||||
|
@ -78,6 +79,11 @@ export const compareMembership = (mship1: MembershipRole, mship2: MembershipRole
|
||||||
export const getByViewerHandler = async ({ ctx, input }: GetByViewerOptions) => {
|
export const getByViewerHandler = async ({ ctx, input }: GetByViewerOptions) => {
|
||||||
const { prisma } = ctx;
|
const { prisma } = ctx;
|
||||||
|
|
||||||
|
await checkRateLimitAndThrowError({
|
||||||
|
identifier: `eventTypes:getByViewer:${ctx.user.id}`,
|
||||||
|
rateLimitingType: "common",
|
||||||
|
});
|
||||||
|
|
||||||
const user = await prisma.user.findUnique({
|
const user = await prisma.user.findUnique({
|
||||||
where: {
|
where: {
|
||||||
id: ctx.user.id,
|
id: ctx.user.id,
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { checkRateLimitAndThrowError } from "@calcom/lib/checkRateLimitAndThrowError";
|
||||||
import { prisma } from "@calcom/prisma";
|
import { prisma } from "@calcom/prisma";
|
||||||
|
|
||||||
import type { TrpcSessionUser } from "../../../trpc";
|
import type { TrpcSessionUser } from "../../../trpc";
|
||||||
|
@ -9,6 +10,10 @@ type ListOptions = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export const listHandler = async ({ ctx }: ListOptions) => {
|
export const listHandler = async ({ ctx }: ListOptions) => {
|
||||||
|
await checkRateLimitAndThrowError({
|
||||||
|
identifier: `eventTypes:list:${ctx.user.id}`,
|
||||||
|
rateLimitingType: "common",
|
||||||
|
});
|
||||||
return await prisma.eventType.findMany({
|
return await prisma.eventType.findMany({
|
||||||
where: {
|
where: {
|
||||||
userId: ctx.user.id,
|
userId: ctx.user.id,
|
||||||
|
|
Loading…
Reference in New Issue