mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-05-19 07:42:43 +00:00
bookmark tweets feature
This commit is contained in:
parent
18511b8005
commit
ee9c598013
3 changed files with 98 additions and 4 deletions
|
|
@ -65,6 +65,14 @@ function SideBar({ jwt }: { jwt: string }) {
|
|||
saveToUser: string;
|
||||
}
|
||||
|
||||
function sendBookmarkedTweetsToAPI(tweets: TweetData[], token: string) {
|
||||
chrome.runtime.sendMessage({
|
||||
type: "sendBookmarkedTweets",
|
||||
jwt: token,
|
||||
tweets,
|
||||
});
|
||||
}
|
||||
|
||||
const fetchBookmarks = () => {
|
||||
const tweets: TweetData[] = []; // Initialize an empty array to hold all tweet elements
|
||||
|
||||
|
|
@ -161,11 +169,9 @@ function SideBar({ jwt }: { jwt: string }) {
|
|||
observer.observe(document.body, { childList: true, subtree: true });
|
||||
|
||||
function downloadTweetsAsJson(tweetsArray: TweetData[]) {
|
||||
setLog([...log, "Saving the tweets to our database..."]);
|
||||
sendBookmarkedTweetsToAPI(tweetsArray, jwt);
|
||||
setIsImportingTweets(false);
|
||||
const jsonData = JSON.stringify(tweetsArray); // Convert the array to JSON
|
||||
|
||||
// TODO: send jsonData to the API
|
||||
console.log(jsonData);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,15 @@ const backendUrl =
|
|||
? "http://localhost:3000"
|
||||
: "https://supermemory.dhr.wtf";
|
||||
|
||||
interface TweetData {
|
||||
tweetText: string;
|
||||
postUrl: string;
|
||||
authorName: string;
|
||||
handle: string;
|
||||
time: string;
|
||||
saveToUser: string;
|
||||
}
|
||||
|
||||
// TODO: Implement getting bookmarks from Twitter API directly
|
||||
// let authorizationHeader: string | null = null;
|
||||
// let csrfToken: string | null = null;
|
||||
|
|
@ -105,4 +114,22 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
|||
// cookies: cookies
|
||||
// });
|
||||
// }
|
||||
else if (request.type === "sendBookmarkedTweets") {
|
||||
const jwt = request.jwt;
|
||||
const tweets = request.tweets as TweetData[];
|
||||
|
||||
(async () => {
|
||||
await fetch(`${backendUrl}/api/vectorizeTweets`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
Authorization: `Bearer ${jwt}`,
|
||||
},
|
||||
body: JSON.stringify(tweets),
|
||||
}).then(async (response) => {
|
||||
return response.json();
|
||||
});
|
||||
})();
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
|
|
|||
61
apps/web/src/app/api/vectorizeTweets/route.ts
Normal file
61
apps/web/src/app/api/vectorizeTweets/route.ts
Normal file
|
|
@ -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,
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue