aboutsummaryrefslogtreecommitdiff
path: root/apps/web/src/app/api
diff options
context:
space:
mode:
authoryxshv <[email protected]>2024-04-15 01:57:39 +0530
committeryxshv <[email protected]>2024-04-15 01:57:39 +0530
commit0ce7c916ffcbf6515c3da521775c72861bddd53c (patch)
treea23c4b9b8bce9b7124c8574ee6f60709b522c6ae /apps/web/src/app/api
parentspace expand layout (diff)
downloadsupermemory-0ce7c916ffcbf6515c3da521775c72861bddd53c.tar.xz
supermemory-0ce7c916ffcbf6515c3da521775c72861bddd53c.zip
add profile and fix drawer scroll
Diffstat (limited to 'apps/web/src/app/api')
-rw-r--r--apps/web/src/app/api/chat/route.ts72
-rw-r--r--apps/web/src/app/api/getCount/route.ts4
2 files changed, 40 insertions, 36 deletions
diff --git a/apps/web/src/app/api/chat/route.ts b/apps/web/src/app/api/chat/route.ts
index c78c9484..374f39cd 100644
--- a/apps/web/src/app/api/chat/route.ts
+++ b/apps/web/src/app/api/chat/route.ts
@@ -69,39 +69,43 @@ export async function POST(req: NextRequest) {
});
}
- const resp = await fetch(
- `https://cf-ai-backend.dhravya.workers.dev/chat?q=${query}&user=${session.user.email ?? session.user.name}&sourcesOnly=${sourcesOnly}&spaces=${spaces}`,
- {
- headers: {
- "X-Custom-Auth-Key": env.BACKEND_SECURITY_KEY,
- },
- method: "POST",
- body: JSON.stringify({
- chatHistory: chatHistory.chatHistory ?? [],
- }),
- },
- );
-
- console.log("sourcesOnly", sourcesOnly);
-
- if (sourcesOnly == "true") {
- const data = await resp.json();
- console.log("data", data);
- return new Response(JSON.stringify(data), { status: 200 });
- }
-
- if (resp.status !== 200 || !resp.ok) {
- const errorData = await resp.json();
- console.log(errorData);
- return new Response(
- JSON.stringify({ message: "Error in CF function", error: errorData }),
- { status: resp.status },
- );
- }
-
- // Stream the response back to the client
- const { readable, writable } = new TransformStream();
- resp && resp.body!.pipeTo(writable);
+ try {
+ const resp = await fetch(
+ `https://cf-ai-backend.dhravya.workers.dev/chat?q=${query}&user=${session.user.email ?? session.user.name}&sourcesOnly=${sourcesOnly}&spaces=${spaces}`,
+ {
+ headers: {
+ "X-Custom-Auth-Key": env.BACKEND_SECURITY_KEY,
+ },
+ method: "POST",
+ body: JSON.stringify({
+ chatHistory: chatHistory.chatHistory ?? [],
+ }),
+ },
+ );
+
+ console.log("sourcesOnly", sourcesOnly);
+
+ if (sourcesOnly == "true") {
+ const data = await resp.json();
+ console.log("data", data);
+ return new Response(JSON.stringify(data), { status: 200 });
+ }
+
+ if (resp.status !== 200 || !resp.ok) {
+ const errorData = await resp.json();
+ console.log(errorData);
+ return new Response(
+ JSON.stringify({ message: "Error in CF function", error: errorData }),
+ { status: resp.status },
+ );
+ }
+
+ // Stream the response back to the client
+ const { readable, writable } = new TransformStream();
+ resp && resp.body!.pipeTo(writable);
+
+ return new Response(readable, { status: 200 });
+ } catch {
+ }
- return new Response(readable, { status: 200 });
}
diff --git a/apps/web/src/app/api/getCount/route.ts b/apps/web/src/app/api/getCount/route.ts
index 3238e58a..9fe54f78 100644
--- a/apps/web/src/app/api/getCount/route.ts
+++ b/apps/web/src/app/api/getCount/route.ts
@@ -1,5 +1,5 @@
import { db } from "@/server/db";
-import { and, eq, sql } from "drizzle-orm";
+import { and, eq, ne, sql } from "drizzle-orm";
import { sessions, storedContent, users } from "@/server/db/schema";
import { type NextRequest, NextResponse } from "next/server";
@@ -66,7 +66,7 @@ export async function GET(req: NextRequest) {
.where(
and(
eq(storedContent.user, session.user.id),
- eq(storedContent.type, "page"),
+ ne(storedContent.type, "twitter-bookmark"),
),
);