aboutsummaryrefslogtreecommitdiff
path: root/apps/web/app/api/store/route.ts
diff options
context:
space:
mode:
Diffstat (limited to 'apps/web/app/api/store/route.ts')
-rw-r--r--apps/web/app/api/store/route.ts25
1 files changed, 24 insertions, 1 deletions
diff --git a/apps/web/app/api/store/route.ts b/apps/web/app/api/store/route.ts
index f9ab7c01..992c2a0e 100644
--- a/apps/web/app/api/store/route.ts
+++ b/apps/web/app/api/store/route.ts
@@ -4,7 +4,7 @@ import { ensureAuth } from "../ensureAuth";
import { z } from "zod";
import { db } from "@/server/db";
import { contentToSpace, space, storedContent } from "@/server/db/schema";
-import { and, eq, inArray } from "drizzle-orm";
+import { and, eq, gt, inArray, sql } from "drizzle-orm";
import { LIMITS } from "@/lib/constants";
import { limit } from "@/app/actions/doers";
@@ -22,6 +22,29 @@ const createMemoryFromAPI = async (input: {
};
}
+ // Get number of items saved in the last 2 hours
+ const last2Hours = new Date(Date.now() - 2 * 60 * 60 * 1000);
+
+ const numberOfItemsSavedInLast2Hours = await db
+ .select({
+ count: sql<number>`count(*)`.mapWith(Number),
+ })
+ .from(storedContent)
+ .where(
+ and(
+ gt(storedContent.savedAt, last2Hours),
+ eq(storedContent.userId, input.userId),
+ ),
+ );
+
+ if (numberOfItemsSavedInLast2Hours[0]!.count >= 20) {
+ return {
+ success: false,
+ data: 0,
+ error: `You have exceeded the limit`,
+ };
+ }
+
const vectorSaveResponse = await fetch(
`${process.env.BACKEND_BASE_URL}/api/add`,
{