Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
feat: add brand logo to cache for faster retrieval
Marc Seitzd9bfec8df0a0
diff --git a/lib/emails/send-email-otp-verification.ts b/lib/emails/send-email-otp-verification.tsindex 5a10379f..585a6962 100644--- a/lib/emails/send-email-otp-verification.ts+++ b/lib/emails/send-email-otp-verification.ts@@ -1,5 +1,6 @@import { getCustomEmail } from "@/lib/edge-config/custom-email";import prisma from "@/lib/prisma";+import { redis } from "@/lib/redis";import { sendEmail } from "@/lib/resend";import OtpEmailVerification from "@/components/emails/otp-verification";@@ -10,26 +11,21 @@ export const sendOtpVerificationEmail = async (isDataroom: boolean = false,teamId: string,) => {- let brand: { logo: string | null } | null = null;+ let logo: string | null = null;let from: string | undefined;const customEmail = await getCustomEmail(teamId);if (customEmail && teamId) {from = customEmail;-- // Get brand logo if we have a custom email- brand = await prisma.brand.findUnique({- where: { id: teamId },- select: { logo: true },- });+ logo = await redis.get(`brand:logo:${teamId}`);}const emailTemplate = OtpEmailVerification({email,code,isDataroom,- logo: brand?.logo ?? undefined,+ logo: logo ?? undefined,});try {diff --git a/pages/api/teams/[teamId]/branding.ts b/pages/api/teams/[teamId]/branding.tsindex a986edf4..7bc17a6a 100644--- a/pages/api/teams/[teamId]/branding.ts+++ b/pages/api/teams/[teamId]/branding.ts@@ -5,6 +5,7 @@ import { getServerSession } from "next-auth";import { errorhandler } from "@/lib/errorHandler";import prisma from "@/lib/prisma";+import { redis } from "@/lib/redis";import { CustomUser } from "@/lib/types";import { authOptions } from "../../auth/[...nextauth]";@@ -74,6 +75,11 @@ export default async function handle(},});+ // Cache the logo URL in Redis if logo exists+ if (logo) {+ await redis.set(`brand:logo:${teamId}`, logo);+ }+return res.status(200).json(brand);} else if (req.method === "PUT") {// PUT /api/teams/:teamId/branding@@ -94,6 +100,14 @@ export default async function handle(},});+ // Update logo in Redis cache+ if (logo) {+ await redis.set(`brand:logo:${teamId}`, logo);+ } else {+ // If logo is null or undefined, delete the cache+ await redis.del(`brand:logo:${teamId}`);+ }+return res.status(200).json(brand);} else if (req.method === "DELETE") {// DELETE /api/teams/:teamId/branding@@ -116,6 +130,9 @@ export default async function handle(},});+ // Remove logo from Redis cache+ await redis.del(`brand:logo:${teamId}`);+return res.status(204).end();} else {// We only allow GET and DELETE requestsdiff --git a/pages/api/teams/[teamId]/index.ts b/pages/api/teams/[teamId]/index.tsindex 195d3979..f00b67e6 100644--- a/pages/api/teams/[teamId]/index.ts+++ b/pages/api/teams/[teamId]/index.ts@@ -9,6 +9,7 @@ import { removeDomainFromVercelProject } from "@/lib/domains";import { errorhandler } from "@/lib/errorHandler";import { deleteFiles } from "@/lib/files/delete-team-files-server";import prisma from "@/lib/prisma";+import { redis } from "@/lib/redis";import { CustomUser } from "@/lib/types";import { unsubscribe } from "@/lib/unsend";@@ -225,6 +226,8 @@ export default async function handle(id: (session.user as CustomUser).id,},}),+ // delete team branding from redis+ redis.del(`brand:logo:${teamId}`),// delete teamprisma.team.delete({where: {