aboutsummaryrefslogtreecommitdiff
path: root/apps/web/src/server
diff options
context:
space:
mode:
authorDhravya <[email protected]>2024-02-28 15:36:39 -0700
committerDhravya <[email protected]>2024-02-28 15:36:39 -0700
commit60012606c8745525ff2862004999185e7d927517 (patch)
tree9bf9cf29a56056f40b355c876926dc4e720e1e38 /apps/web/src/server
parentextension auth and sync working (diff)
downloadsupermemory-60012606c8745525ff2862004999185e7d927517.tar.xz
supermemory-60012606c8745525ff2862004999185e7d927517.zip
implemented AI with citations and extension flow, using openai embedder
Diffstat (limited to 'apps/web/src/server')
-rw-r--r--apps/web/src/server/auth.ts20
-rw-r--r--apps/web/src/server/db/schema.ts38
-rw-r--r--apps/web/src/server/helpers.ts34
3 files changed, 79 insertions, 13 deletions
diff --git a/apps/web/src/server/auth.ts b/apps/web/src/server/auth.ts
index e5bac1f0..3ceb7ac9 100644
--- a/apps/web/src/server/auth.ts
+++ b/apps/web/src/server/auth.ts
@@ -10,16 +10,16 @@ export const {
} = NextAuth({
secret: env.NEXTAUTH_SECRET,
trustHost: true,
- callbacks: {
- session: ({ session, token }) => ({
- ...session,
- user: {
- // ...session.user,
- id: token.id as string,
- token: token,
- },
- })
- },
+ // callbacks: {
+ // session: ({ session, token }) => ({
+ // ...session,
+ // user: {
+ // // ...session.user,
+ // id: token.id as string,
+ // token: token,
+ // },
+ // })
+ // },
adapter: DrizzleAdapter(db),
providers: [
Google({
diff --git a/apps/web/src/server/db/schema.ts b/apps/web/src/server/db/schema.ts
index 888445ae..d473ef2d 100644
--- a/apps/web/src/server/db/schema.ts
+++ b/apps/web/src/server/db/schema.ts
@@ -5,8 +5,9 @@ import {
primaryKey,
sqliteTableCreator,
text,
+ integer,
+ unique
} from "drizzle-orm/sqlite-core";
-import { type AdapterAccount } from "next-auth/adapters";
/**
* This is an example of how to use the multi-project schema feature of Drizzle ORM. Use the same
@@ -32,7 +33,7 @@ export const usersRelations = relations(users, ({ many }) => ({
export const accounts = createTable(
"account",
{
- id: text("id", { length: 255 }).notNull().primaryKey(),
+ id: integer("id").notNull().primaryKey({ autoIncrement: true }),
userId: text("userId", { length: 255 }).notNull().references(() => users.id),
type: text("type", { length: 255 }).notNull(),
provider: text("provider", { length: 255 }).notNull(),
@@ -55,7 +56,7 @@ export const accounts = createTable(
export const sessions = createTable(
"session",
{
- id: text("id", { length: 255 }).notNull().primaryKey(),
+ id: integer("id").notNull().primaryKey({ autoIncrement: true }),
sessionToken: text("sessionToken", { length: 255 }).notNull(),
userId: text("userId", { length: 255 }).notNull().references(() => users.id),
expires: int("expires", { mode: "timestamp" }).notNull(),
@@ -75,4 +76,35 @@ export const verificationTokens = createTable(
(vt) => ({
compoundKey: primaryKey({ columns: [vt.identifier, vt.token] }),
})
+);
+
+export const userStoredContent = createTable(
+ "userStoredContent",
+ {
+ userId: text("userId").notNull().references(() => users.id),
+ contentId: integer("contentId").notNull().references(() => storedContent.id),
+ },
+ (usc) => ({
+ userContentIdx: index("userStoredContent_idx").on(usc.userId, usc.contentId),
+ uniqueUserContent: unique("unique_user_content").on(usc.userId, usc.contentId),
+ })
+);
+
+export const storedContent = createTable(
+ "storedContent",
+ {
+ id: integer("id").notNull().primaryKey({ autoIncrement: true }),
+ content: text("content").notNull(),
+ title: text("title", { length: 255 }),
+ description: text("description", { length: 255 }),
+ url: text("url").notNull().unique(),
+ savedAt: int("savedAt", { mode: "timestamp" }).notNull(),
+ baseUrl: text("baseUrl", { length: 255 }),
+ image: text("image", { length: 255 }),
+ },
+ (sc) => ({
+ urlIdx: index("storedContent_url_idx").on(sc.url),
+ savedAtIdx: index("storedContent_savedAt_idx").on(sc.savedAt),
+ titleInx: index("storedContent_title_idx").on(sc.title),
+ })
); \ No newline at end of file
diff --git a/apps/web/src/server/helpers.ts b/apps/web/src/server/helpers.ts
new file mode 100644
index 00000000..1f6cf977
--- /dev/null
+++ b/apps/web/src/server/helpers.ts
@@ -0,0 +1,34 @@
+export async function getMetaData(url: string) {
+ const response = await fetch(url);
+ const html = await response.text();
+
+ // Extract the base URL
+ const baseUrl = new URL(url).origin;
+
+ // Extract title
+ const titleMatch = html.match(/<title>(.*?)<\/title>/);
+ const title = titleMatch ? titleMatch[1] : 'Title not found';
+
+ // Extract meta description
+ const descriptionMatch = html.match(
+ /<meta name="description" content="(.*?)"\s*\/?>/,
+ );
+ const description = descriptionMatch
+ ? descriptionMatch[1]
+ : 'Description not found';
+
+ // Extract Open Graph image
+ const imageMatch = html.match(
+ /<meta property="og:image" content="(.*?)"\s*\/?>/,
+ );
+ const image = imageMatch ? imageMatch[1] : 'Image not found';
+
+ // Prepare the metadata object
+ const metadata = {
+ title,
+ description,
+ image,
+ baseUrl,
+ };
+ return metadata;
+ } \ No newline at end of file