aboutsummaryrefslogtreecommitdiff
path: root/apps/web/src/app/api
diff options
context:
space:
mode:
authorDhravya <[email protected]>2024-04-13 20:10:51 -0700
committerDhravya <[email protected]>2024-04-13 20:10:51 -0700
commit439032568ad3b9e9c79d36c81469fea8f044b345 (patch)
treef15a4d6c79fbbd5e1e334ba3b9a7eee677438875 /apps/web/src/app/api
parentfix layout (diff)
downloadsupermemory-439032568ad3b9e9c79d36c81469fea8f044b345.tar.xz
supermemory-439032568ad3b9e9c79d36c81469fea8f044b345.zip
add page data to vector db
Diffstat (limited to 'apps/web/src/app/api')
-rw-r--r--apps/web/src/app/api/store/route.ts44
1 files changed, 27 insertions, 17 deletions
diff --git a/apps/web/src/app/api/store/route.ts b/apps/web/src/app/api/store/route.ts
index d592bc53..7fa92b16 100644
--- a/apps/web/src/app/api/store/route.ts
+++ b/apps/web/src/app/api/store/route.ts
@@ -71,7 +71,6 @@ export async function POST(req: NextRequest) {
};
const metadata = await getMetaData(data.url);
-
let storeToSpaces = data.spaces;
if (!storeToSpaces) {
@@ -87,16 +86,21 @@ export async function POST(req: NextRequest) {
console.log("count", count[0].count);
- const { id } = (await db.insert(storedContent).values({
- content: data.pageContent,
- title: metadata.title,
- description: metadata.description,
- url: data.url,
- baseUrl: metadata.baseUrl,
- image: metadata.image,
- savedAt: new Date(),
- user: session.user.id,
- }).returning({ id: storedContent.id }))[0];
+ const { id } = (
+ await db
+ .insert(storedContent)
+ .values({
+ content: data.pageContent,
+ title: metadata.title,
+ description: metadata.description,
+ url: data.url,
+ baseUrl: metadata.baseUrl,
+ image: metadata.image,
+ savedAt: new Date(),
+ user: session.user.id,
+ })
+ .returning({ id: storedContent.id })
+ )[0];
if (!id) {
return NextResponse.json(
@@ -108,12 +112,18 @@ export async function POST(req: NextRequest) {
const spaceData = await db
.select()
.from(space)
- .where(and(inArray(space.name, storeToSpaces), eq(space.user, session.user.id)))
- .all()
-
- await Promise.all([spaceData.forEach(async space => {
- await db.insert(contentToSpace).values({ contentId: id, spaceId: space.id })
- })])
+ .where(
+ and(inArray(space.name, storeToSpaces), eq(space.user, session.user.id)),
+ )
+ .all();
+
+ await Promise.all([
+ spaceData.forEach(async (space) => {
+ await db
+ .insert(contentToSpace)
+ .values({ contentId: id, spaceId: space.id });
+ }),
+ ]);
const res = (await Promise.race([
fetch("https://cf-ai-backend.dhravya.workers.dev/add", {