CI / Docker image (push) Successful in 12s
CI / Server (push) Successful in 25s
CI / CLI (push) Successful in 13s
Development image / Development image (push) Successful in 21s
CI / CLI (windows) (push) Successful in 57s
CI / CLI (linux-arm64, static) (push) Successful in 1m37s
Release / Prepare release (push) Successful in 2s
Release / Server (linux-x64) (push) Successful in 53s
Release / CLI (linux-arm64, static) (push) Successful in 1m32s
Release / Docker image (push) Successful in 2m48s
Release / Server (windows-x64) (push) Successful in 6m20s
Release / CLI (windows-x64) (push) Successful in 6m48s
Release / CLI (linux-x64) (push) Successful in 7m8s
Release / Publish release (push) Successful in 1s
Squash the tree into one commit, drop docs/architecture.html, reset the version line to 0.3.0, consolidate the changelog, enable Renovate automerge for non-major updates and add AGENTS.md.
41 lines
1.2 KiB
JavaScript
41 lines
1.2 KiB
JavaScript
const WINDOW = 15 * 60 * 1000;
|
|
const MAX_FAILURES = 20;
|
|
const MAX_KEYS = 10_000;
|
|
|
|
class AttemptLimiter {
|
|
constructor({ window = WINDOW, max = MAX_FAILURES } = {}) {
|
|
this.window = window;
|
|
this.max = max;
|
|
this.failures = new Map();
|
|
this.sweeper = setInterval(() => this.sweep(), window);
|
|
this.sweeper.unref();
|
|
}
|
|
|
|
blocked(key) {
|
|
const entry = this.failures.get(key);
|
|
if (!entry) return false;
|
|
if (Date.now() - entry.since > this.window) { this.failures.delete(key); return false; }
|
|
return entry.count >= this.max;
|
|
}
|
|
|
|
record(key) {
|
|
const now = Date.now();
|
|
const entry = this.failures.get(key);
|
|
if (entry && now - entry.since <= this.window) { entry.count += 1; return; }
|
|
if (this.failures.size >= MAX_KEYS) this.sweep();
|
|
if (this.failures.size >= MAX_KEYS) this.failures.delete(this.failures.keys().next().value);
|
|
this.failures.set(key, { count: 1, since: now });
|
|
}
|
|
|
|
forget(key) {
|
|
this.failures.delete(key);
|
|
}
|
|
|
|
sweep() {
|
|
const now = Date.now();
|
|
for (const [key, entry] of this.failures) if (now - entry.since > this.window) this.failures.delete(key);
|
|
}
|
|
}
|
|
|
|
module.exports = { AttemptLimiter };
|