Skip to content

Node.js based forum software built for the modern web

332 B
Raw Blame
'use strict';

const db = require('./database');

const Ratelimit = module.exports;

Ratelimit.check = async function (key, { window, max }) {
	const count = await db.increment(key);
	if (count === 1) {
		await db.pexpire(key, window);
	}
	return count <= max;
};

Ratelimit.clear = async function (key) {
	await db.delete(key);
};