aboutsummaryrefslogtreecommitdiff
path: root/apps/web/src/app/api
diff options
context:
space:
mode:
authorDhravya <[email protected]>2024-04-12 23:22:51 -0700
committerDhravya <[email protected]>2024-04-12 23:22:51 -0700
commitee9c598013deb9cf20882e6971267942d0832d7b (patch)
tree021cf9ca808d1df024d7f63b007eb7bcecc49aac /apps/web/src/app/api
parentmark runtime=edge for spaces (diff)
downloadsupermemory-ee9c598013deb9cf20882e6971267942d0832d7b.tar.xz
supermemory-ee9c598013deb9cf20882e6971267942d0832d7b.zip
bookmark tweets feature
Diffstat (limited to 'apps/web/src/app/api')
-rw-r--r--apps/web/src/app/api/vectorizeTweets/route.ts61
1 files changed, 61 insertions, 0 deletions
diff --git a/apps/web/src/app/api/vectorizeTweets/route.ts b/apps/web/src/app/api/vectorizeTweets/route.ts
new file mode 100644
index 00000000..5dfb22f1
--- /dev/null
+++ b/apps/web/src/app/api/vectorizeTweets/route.ts
@@ -0,0 +1,61 @@
+import { db } from "@/server/db";
+import { eq } from "drizzle-orm";
+import { sessions, storedContent, users } from "@/server/db/schema";
+import { type NextRequest, NextResponse } from "next/server";
+import { env } from "@/env";
+
+export const runtime = "edge";
+
+interface TweetData {
+ tweetText: string;
+ postUrl: string;
+ authorName: string;
+ handle: string;
+ time: string;
+ saveToUser: string;
+}
+
+export async function POST(req: NextRequest) {
+ const token =
+ req.cookies.get("next-auth.session-token")?.value ??
+ req.cookies.get("__Secure-authjs.session-token")?.value ??
+ req.cookies.get("authjs.session-token")?.value ??
+ req.headers.get("Authorization")?.replace("Bearer ", "");
+
+ if (!token) {
+ return new Response(
+ JSON.stringify({ message: "Invalid Key, session not found." }),
+ { status: 404 },
+ );
+ }
+
+ const sessionData = await db
+ .select()
+ .from(sessions)
+ .where(eq(sessions.sessionToken, token!));
+
+ if (!sessionData || sessionData.length === 0) {
+ return new Response(
+ JSON.stringify({ message: "Invalid Key, session not found." }),
+ { status: 404 },
+ );
+ }
+
+ const body = (await req.json()) as TweetData[];
+
+ const resp = await fetch(
+ `https://cf-ai-backend.dhravya.workers.dev/batchUploadTweets`,
+ {
+ headers: {
+ "X-Custom-Auth-Key": env.BACKEND_SECURITY_KEY,
+ },
+ method: "POST",
+ body: JSON.stringify(body),
+ },
+ );
+
+ return new Response(await resp.text(), {
+ status: resp.status,
+ headers: resp.headers,
+ });
+}