diff options
| author | Dhravya Shah <[email protected]> | 2024-06-18 17:58:46 -0500 |
|---|---|---|
| committer | Dhravya Shah <[email protected]> | 2024-06-18 17:58:46 -0500 |
| commit | f4bb71e8f7e07bb2e919b7f222d5acb2905eb8f2 (patch) | |
| tree | 7310dc521ef3559055bbe71f50c3861be2fa0503 /apps/web/app/helpers | |
| parent | darkmode by default - so that the colors don't f up on lightmode devices (diff) | |
| parent | Create Embeddings for Canvas (diff) | |
| download | supermemory-default-darkmode.tar.xz supermemory-default-darkmode.zip | |
Diffstat (limited to 'apps/web/app/helpers')
| -rw-r--r-- | apps/web/app/helpers/lib/get-metadata.ts | 40 | ||||
| -rw-r--r-- | apps/web/app/helpers/lib/get-theme-button.tsx | 11 | ||||
| -rw-r--r-- | apps/web/app/helpers/lib/handle-errors.ts | 25 | ||||
| -rw-r--r-- | apps/web/app/helpers/lib/searchParams.ts | 26 | ||||
| -rw-r--r-- | apps/web/app/helpers/server/auth.ts | 29 | ||||
| -rw-r--r-- | apps/web/app/helpers/server/db/index.ts | 5 | ||||
| -rw-r--r-- | apps/web/app/helpers/server/db/schema.ts | 143 |
7 files changed, 0 insertions, 279 deletions
diff --git a/apps/web/app/helpers/lib/get-metadata.ts b/apps/web/app/helpers/lib/get-metadata.ts deleted file mode 100644 index 4609e49b..00000000 --- a/apps/web/app/helpers/lib/get-metadata.ts +++ /dev/null @@ -1,40 +0,0 @@ -"use server"; -import * as cheerio from "cheerio"; - -// TODO: THIS SHOULD PROBABLY ALSO FETCH THE OG-IMAGE -export async function getMetaData(url: string) { - const response = await fetch(url); - const html = await response.text(); - - const $ = cheerio.load(html); - - // Extract the base URL - const baseUrl = new URL(url).origin; - - // Extract title - const title = $("title").text().trim(); - - const description = $("meta[name=description]").attr("content") ?? ""; - - const _favicon = - $("link[rel=icon]").attr("href") ?? "https://supermemory.dhr.wtf/web.svg"; - - let favicon = - _favicon.trim().length > 0 - ? _favicon.trim() - : "https://supermemory.dhr.wtf/web.svg"; - if (favicon.startsWith("/")) { - favicon = baseUrl + favicon; - } else if (favicon.startsWith("./")) { - favicon = baseUrl + favicon.slice(1); - } - - // Prepare the metadata object - const metadata = { - title, - description, - image: favicon, - baseUrl, - }; - return metadata; -} diff --git a/apps/web/app/helpers/lib/get-theme-button.tsx b/apps/web/app/helpers/lib/get-theme-button.tsx deleted file mode 100644 index 020cc976..00000000 --- a/apps/web/app/helpers/lib/get-theme-button.tsx +++ /dev/null @@ -1,11 +0,0 @@ -// Theming that works perfectly with app router (no flicker, jumps etc!) - -import dynamic from "next/dynamic"; - -// Don't SSR the toggle since the value on the server will be different than the client -export const getThemeToggler = () => - dynamic(() => import("@repo/ui/shadcn/theme-toggle"), { - ssr: false, - // Make sure to code a placeholder so the UI doesn't jump when the component loads - loading: () => <div className="w-6 h-6" />, - }); diff --git a/apps/web/app/helpers/lib/handle-errors.ts b/apps/web/app/helpers/lib/handle-errors.ts deleted file mode 100644 index 42cae589..00000000 --- a/apps/web/app/helpers/lib/handle-errors.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { isRedirectError } from "next/dist/client/components/redirect"; -import { toast } from "sonner"; -import { z } from "zod"; - -export function getErrorMessage(err: unknown) { - const unknownError = "Something went wrong, please try again later."; - - if (err instanceof z.ZodError) { - const errors = err.issues.map((issue) => { - return issue.message; - }); - return errors.join("\n"); - } else if (err instanceof Error) { - return err.message; - } else if (isRedirectError(err)) { - throw err; - } else { - return unknownError; - } -} - -export function showErrorToast(err: unknown) { - const errorMessage = getErrorMessage(err); - return toast.error(errorMessage); -} diff --git a/apps/web/app/helpers/lib/searchParams.ts b/apps/web/app/helpers/lib/searchParams.ts deleted file mode 100644 index 9899eaf7..00000000 --- a/apps/web/app/helpers/lib/searchParams.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { - createSearchParamsCache, - parseAsInteger, - parseAsString, - parseAsBoolean, - parseAsArrayOf, - parseAsJson, -} from "nuqs/server"; -import { z } from "zod"; - -export const homeSearchParamsCache = createSearchParamsCache({ - firstTime: parseAsBoolean.withDefault(false), -}); - -export const chatSearchParamsCache = createSearchParamsCache({ - firstTime: parseAsBoolean.withDefault(false), - q: parseAsString.withDefault(""), - spaces: parseAsArrayOf( - parseAsJson(() => - z.object({ - id: z.string(), - name: z.string(), - }), - ), - ).withDefault([]), -}); diff --git a/apps/web/app/helpers/server/auth.ts b/apps/web/app/helpers/server/auth.ts deleted file mode 100644 index 73119d87..00000000 --- a/apps/web/app/helpers/server/auth.ts +++ /dev/null @@ -1,29 +0,0 @@ -import NextAuth, { NextAuthResult } from "next-auth"; -import Google from "next-auth/providers/google"; -import { DrizzleAdapter } from "@auth/drizzle-adapter"; -import { db } from "./db"; - -export const { - handlers: { GET, POST }, - signIn, - signOut, - auth, -} = NextAuth({ - secret: process.env.BACKEND_SECURITY_KEY, - callbacks: { - session: ({ session, token, user }) => ({ - ...session, - user: { - ...session.user, - id: user.id, - }, - }), - }, - adapter: DrizzleAdapter(db), - providers: [ - Google({ - clientId: process.env.GOOGLE_CLIENT_ID, - clientSecret: process.env.GOOGLE_CLIENT_SECRET, - }), - ], -}); diff --git a/apps/web/app/helpers/server/db/index.ts b/apps/web/app/helpers/server/db/index.ts deleted file mode 100644 index 4d671bea..00000000 --- a/apps/web/app/helpers/server/db/index.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { drizzle } from "drizzle-orm/d1"; - -import * as schema from "./schema"; - -export const db = drizzle(process.env.DATABASE, { schema, logger: true }); diff --git a/apps/web/app/helpers/server/db/schema.ts b/apps/web/app/helpers/server/db/schema.ts deleted file mode 100644 index c4616eb2..00000000 --- a/apps/web/app/helpers/server/db/schema.ts +++ /dev/null @@ -1,143 +0,0 @@ -import { relations, sql } from "drizzle-orm"; -import { - index, - int, - primaryKey, - sqliteTableCreator, - text, - integer, -} from "drizzle-orm/sqlite-core"; - -export const createTable = sqliteTableCreator((name) => `${name}`); - -export const users = createTable("user", { - id: text("id", { length: 255 }).notNull().primaryKey(), - name: text("name", { length: 255 }), - email: text("email", { length: 255 }).notNull(), - emailVerified: int("emailVerified", { mode: "timestamp" }).default( - sql`CURRENT_TIMESTAMP`, - ), - image: text("image", { length: 255 }), -}); - -export type User = typeof users.$inferSelect; - -export const usersRelations = relations(users, ({ many }) => ({ - accounts: many(accounts), - sessions: many(sessions), -})); - -export const accounts = createTable( - "account", - { - id: integer("id").notNull().primaryKey({ autoIncrement: true }), - userId: text("userId", { length: 255 }) - .notNull() - .references(() => users.id, { onDelete: "cascade" }), - type: text("type", { length: 255 }).notNull(), - provider: text("provider", { length: 255 }).notNull(), - providerAccountId: text("providerAccountId", { length: 255 }).notNull(), - refresh_token: text("refresh_token"), - access_token: text("access_token"), - expires_at: int("expires_at"), - token_type: text("token_type", { length: 255 }), - scope: text("scope", { length: 255 }), - id_token: text("id_token"), - session_state: text("session_state", { length: 255 }), - oauth_token_secret: text("oauth_token_secret"), - oauth_token: text("oauth_token"), - }, - (account) => ({ - userIdIdx: index("account_userId_idx").on(account.userId), - }), -); - -export const sessions = createTable( - "session", - { - id: integer("id").notNull().primaryKey({ autoIncrement: true }), - sessionToken: text("sessionToken", { length: 255 }).notNull(), - userId: text("userId", { length: 255 }) - .notNull() - .references(() => users.id, { onDelete: "cascade" }), - expires: int("expires", { mode: "timestamp" }).notNull(), - }, - (session) => ({ - userIdIdx: index("session_userId_idx").on(session.userId), - }), -); - -export const verificationTokens = createTable( - "verificationToken", - { - identifier: text("identifier", { length: 255 }).notNull(), - token: text("token", { length: 255 }).notNull(), - expires: int("expires", { mode: "timestamp" }).notNull(), - }, - (vt) => ({ - compoundKey: primaryKey({ columns: [vt.identifier, vt.token] }), - }), -); - -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(), - savedAt: int("savedAt", { mode: "timestamp" }).notNull(), - baseUrl: text("baseUrl", { length: 255 }), - ogImage: text("ogImage", { length: 255 }), - type: text("type", { enum: ["note", "page", "twitter-bookmark"] }).default( - "page", - ), - image: text("image", { length: 255 }), - user: text("user", { length: 255 }).references(() => users.id, { - onDelete: "cascade", - }), - }, - (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), - userIdx: index("storedContent_user_idx").on(sc.user), - }), -); - -export const contentToSpace = createTable( - "contentToSpace", - { - contentId: integer("contentId") - .notNull() - .references(() => storedContent.id, { onDelete: "cascade" }), - spaceId: integer("spaceId") - .notNull() - .references(() => space.id, { onDelete: "cascade" }), - }, - (cts) => ({ - compoundKey: primaryKey({ columns: [cts.contentId, cts.spaceId] }), - }), -); - -export const space = createTable( - "space", - { - id: integer("id").notNull().primaryKey({ autoIncrement: true }), - name: text("name").notNull().unique().default("none"), - user: text("user", { length: 255 }).references(() => users.id, { - onDelete: "cascade", - }), - }, - (space) => ({ - nameIdx: index("spaces_name_idx").on(space.name), - userIdx: index("spaces_user_idx").on(space.user), - }), -); - -export type StoredContent = Omit<typeof storedContent.$inferSelect, "user">; -export type StoredSpace = typeof space.$inferSelect; -export type ChachedSpaceContent = StoredContent & { - space: number; -}; |