release: WRNexusJS 0.4.0
This commit is contained in:
1 parent
8b728a3e5d
commit
30e5721e84
250 files changed
+10065
-3923
No files matched your search
@@ -1,8 +1,4 @@
|
||||
import type {
|
||||
CaptchaChallengeRecord,
|
||||
CaptchaResponseTokenRecord,
|
||||
CaptchaStore,
|
||||
} from "../types.ts";
|
||||
import type { CaptchaChallengeRecord, CaptchaResponseTokenRecord, CaptchaStore } from "../types.ts";
|
||||
|
||||
function cloneChallenge(record: CaptchaChallengeRecord): CaptchaChallengeRecord {
|
||||
return structuredClone(record);
|
||||
@@ -72,7 +68,10 @@ export class MemoryCaptchaStore implements CaptchaStore {
|
||||
return record ? cloneToken(record) : undefined;
|
||||
}
|
||||
|
||||
async consumeToken(tokenHash: string, now: number): Promise<CaptchaResponseTokenRecord | undefined> {
|
||||
async consumeToken(
|
||||
tokenHash: string,
|
||||
now: number,
|
||||
): Promise<CaptchaResponseTokenRecord | undefined> {
|
||||
const record = this.tokens.get(tokenHash);
|
||||
if (!record || record.expiresAt <= now || record.consumedAt) return undefined;
|
||||
record.consumedAt = now;
|
||||
@@ -96,7 +95,11 @@ export class MemoryCaptchaStore implements CaptchaStore {
|
||||
}
|
||||
}
|
||||
|
||||
private evict<T extends { expiresAt: number }>(map: Map<string, T>, max: number, now: number): void {
|
||||
private evict<T extends { expiresAt: number }>(
|
||||
map: Map<string, T>,
|
||||
max: number,
|
||||
now: number,
|
||||
): void {
|
||||
for (const [key, record] of map) if (record.expiresAt <= now) map.delete(key);
|
||||
while (map.size >= max) map.delete(map.keys().next().value!);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user