Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,7 @@ function checkMemoryLimit(
const active = (memoryBuckets.get(key) ?? []).filter(
(timestamp) => timestamp > cutoff
);
const reset = Math.ceil(
((active[0] ?? now) + WINDOW_SECONDS * 1000) / 1000
);
const reset = Math.ceil(((active[0] ?? now) + WINDOW_SECONDS * 1000) / 1000);

if (active.length >= limit) {
memoryBuckets.set(key, active);
Expand Down Expand Up @@ -172,7 +170,7 @@ async function checkUpstashLimit(
}

const data = await response.json();

// Upstash REST eval response format: { result: [allowed_flag, current_count] }
const [allowedFlag, currentCount] = data.result as [number, number];
const isAllowed = allowedFlag === 1;
Expand All @@ -184,7 +182,10 @@ async function checkUpstashLimit(
reset,
};
} catch (error) {
console.error("Rate-limiter cloud pipeline failure, falling back to local memory storage:", error);
console.error(
"Rate-limiter cloud pipeline failure, falling back to local memory storage:",
error
);
return null;
}
}
Expand Down
Loading