Add incr on block.

This commit is contained in:
Brian Cao 2023-06-01 12:49:28 -07:00
parent 968574dda1
commit 7e587198dd
2 changed files with 8 additions and 0 deletions

View File

@ -54,6 +54,11 @@ async function fetchUserBlock(userId: string) {
return redis.get(key);
}
async function incrementUserBlock(userId: string) {
const key = `user:block:${userId}`;
return redis.incr(key);
}
export default {
fetchWebsite,
storeWebsite,
@ -65,5 +70,6 @@ export default {
storeSession,
deleteSession,
fetchUserBlock,
incrementUserBlock,
enabled: redis.enabled,
};

View File

@ -99,6 +99,8 @@ export async function findSession(req: NextApiRequestCollect) {
async function checkUserBlock(userId: string) {
if (process.env.ENABLE_BLOCKER && (await cache.fetchUserBlock(userId))) {
await cache.incrementUserBlock(userId);
throw new Error('Usage Limit.');
}
}