mirror of
https://github.com/bretzel-app/crumbs.git
synced 2026-10-12 20:06:57 +02:00
- POST/DELETE /api/notes/[id]/share for creating/revoking public links - GET /api/shared/[token] for fetching shared note data (no auth) - GET /api/shared/[token]/attachment/[attachmentId] for public images - Add /s/ and /api/shared to PUBLIC_PATHS in auth middleware - Add IP-based rate limiter (60 req/min) for public endpoints Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
15 lines
424 B
TypeScript
15 lines
424 B
TypeScript
const store = new Map<string, { count: number; windowStart: number }>();
|
|
const WINDOW_MS = 60_000; // 1 minute
|
|
const MAX_REQUESTS = 60;
|
|
|
|
export function checkIpRateLimit(ip: string): boolean {
|
|
const now = Date.now();
|
|
const entry = store.get(ip);
|
|
if (!entry || now - entry.windowStart > WINDOW_MS) {
|
|
store.set(ip, { count: 1, windowStart: now });
|
|
return true;
|
|
}
|
|
entry.count++;
|
|
return entry.count <= MAX_REQUESTS;
|
|
}
|