feat(rate-limit): add rate limit configuration for comment export

This commit is contained in:
Yusuf İpek
2026-04-10 21:12:56 +03:00
parent 84ea384ee7
commit d07b40a937
2 changed files with 4 additions and 2 deletions
@@ -13,12 +13,11 @@ import { logError } from '@/lib/logger';
type RouteParams = { params: Promise<{ versionId: string }> }; type RouteParams = { params: Promise<{ versionId: string }> };
const MAX_EXPORT_COMMENTS = 5000; const MAX_EXPORT_COMMENTS = 5000;
const EXPORT_RATE_LIMIT = { windowMs: 60 * 1000, maxRequests: 10 };
// GET /api/versions/[versionId]/comments/export?format=csv|pdf&includeResolved=true|false // GET /api/versions/[versionId]/comments/export?format=csv|pdf&includeResolved=true|false
export async function GET(request: NextRequest, { params }: RouteParams) { export async function GET(request: NextRequest, { params }: RouteParams) {
try { try {
const limited = await rateLimit(request, 'comment-export', EXPORT_RATE_LIMIT); const limited = await rateLimit(request, 'comment-export');
if (limited) return limited; if (limited) return limited;
const session = await auth(); const session = await auth();
+3
View File
@@ -56,6 +56,9 @@ export const RATE_LIMIT_CONFIGS: Record<string, RateLimitConfig> = {
// Watch progress — allow frequent updates but prevent abuse // Watch progress — allow frequent updates but prevent abuse
'watch-progress': { windowMs: 60 * 1000, maxRequests: 30 }, // 30 per minute (pausing + periodic + visibility changes) 'watch-progress': { windowMs: 60 * 1000, maxRequests: 30 }, // 30 per minute (pausing + periodic + visibility changes)
// Exports
'comment-export': { windowMs: 60 * 1000, maxRequests: 10 }, // 10 per minute
// Downloads — strict enough to limit upstream probing/cost abuse // Downloads — strict enough to limit upstream probing/cost abuse
'video-download': { windowMs: 60 * 1000, maxRequests: 8 }, // 8 per minute 'video-download': { windowMs: 60 * 1000, maxRequests: 8 }, // 8 per minute
'video-download-prepare': { windowMs: 60 * 1000, maxRequests: 5 }, // 5 per minute 'video-download-prepare': { windowMs: 60 * 1000, maxRequests: 5 }, // 5 per minute