feat: ratelimit

This commit is contained in:
diced
2024-06-01 17:19:16 -07:00
parent 1b6bdd8634
commit 32a295e3f0
8 changed files with 101 additions and 13 deletions
+12 -1
View File
@@ -263,6 +263,17 @@ export const schema = z.object({
})
.nullable()
.default(null),
ratelimit: z.object({
enabled: z.boolean().default(true),
max: z.number().default(10),
window: z
.number()
.nullable()
.default(null)
.refine((v) => (v ? v > 0 : true)),
adminBypass: z.boolean().default(true),
allowList: z.array(z.string()).default([]),
}),
});
export type Config = z.infer<typeof schema>;
@@ -320,7 +331,7 @@ function handleError(error: ZodIssue) {
const path =
error.path[1] === 'externalLinks'
? `WEBSITE_EXTERNAL_LINKS[${error.path[2]}]`
: PROP_TO_ENV[error.path.join('.')] ?? error.path.join('.');
: PROP_TO_ENV[<keyof typeof PROP_TO_ENV>error.path.join('.')] ?? error.path.join('.');
logger.error(`${path}: ${error.message}`);
}