Skip to content

armgit / umami

Public Imported from GitHub
0

Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.

Add incr on block.

Brian Cao7e587198ddda
diff --git a/lib/cache.ts b/lib/cache.ts
index e63a53bbd..7ee7bf287 100644
--- a/lib/cache.ts
+++ b/lib/cache.ts
@@ -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,
};
diff --git a/lib/session.ts b/lib/session.ts
index 1fedb91b8..7fa062153 100644
--- a/lib/session.ts
+++ b/lib/session.ts
@@ -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.');
}
}