Files
at-mintel/packages/next-utils/src/index.ts
Marc Mintel 7702310a9c
All checks were successful
Monorepo Pipeline / ⚡ Prioritize Release (push) Successful in 3s
Monorepo Pipeline / 🧹 Lint (push) Successful in 1m19s
Monorepo Pipeline / 🧪 Test (push) Successful in 1m5s
Monorepo Pipeline / 🏗️ Build (push) Successful in 1m26s
Monorepo Pipeline / 🚀 Release (push) Has been skipped
Monorepo Pipeline / 🐳 Build Image Processor (push) Has been skipped
Monorepo Pipeline / 🐳 Build Directus (Base) (push) Has been skipped
Monorepo Pipeline / 🐳 Build Gatekeeper (Product) (push) Has been skipped
Monorepo Pipeline / 🐳 Build Build-Base (push) Has been skipped
Monorepo Pipeline / 🐳 Build Production Runtime (push) Has been skipped
chore: remove Directus CMS and related dependencies
2026-02-27 19:06:06 +01:00

37 lines
940 B
TypeScript

// Simple in-memory rate limiting
const submissions: Record<string, number> = {};
const RATE_LIMIT_WINDOW = 60 * 60 * 1000; // 1 hour
const MAX_SUBMISSIONS_PER_WINDOW = 3;
export async function rateLimit(
identifier: string,
windowMs = RATE_LIMIT_WINDOW,
maxSubmissions = MAX_SUBMISSIONS_PER_WINDOW,
) {
const now = Date.now();
// Clean up old submissions
Object.keys(submissions).forEach((key) => {
if (now - submissions[key] > windowMs) {
delete submissions[key];
}
});
// Check if identifier has exceeded submission limit
const currentSubmissions = Object.values(submissions).filter(
(timestamp) => now - timestamp <= windowMs,
);
if (currentSubmissions.length >= maxSubmissions) {
throw new Error("Too many submissions. Please try again later.");
}
// Record this submission
submissions[identifier] = now;
}
export * from "./lang";
export * from "./i18n";
export * from "./env";