type Window = { count: number; resetAt: number }; const windows = new Map(); export function assertUnderRateLimit(key: string, max: number, windowMs: number) { const now = Date.now(); let w = windows.get(key); if (!w || now > w.resetAt) { w = { count: 0, resetAt: now + windowMs }; windows.set(key, w); } w.count += 1; if (w.count > max) { throw createError({ statusCode: 429, statusMessage: "请求过于频繁,请稍后再试", }); } }