Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
fix: watermark enabled without config
Marc Seitzfbb6d8471d1a
diff --git a/components/links/link-sheet/watermark-section.tsx b/components/links/link-sheet/watermark-section.tsxindex dc9bf9db..1cf6093c 100644--- a/components/links/link-sheet/watermark-section.tsx+++ b/components/links/link-sheet/watermark-section.tsx@@ -55,17 +55,6 @@ export default function WatermarkSection({}}, [presets, isAllowed]);- const handleWatermarkToggle = () => {- const updatedWatermark = !enabled;-- setData({- ...data,- enableWatermark: updatedWatermark,- watermarkConfig: watermarkConfig || null,- });- setEnabled(updatedWatermark);- };-const initialconfig: WatermarkConfig = {text: watermarkConfig?.text ?? "",isTiled: watermarkConfig?.isTiled ?? false,@@ -76,6 +65,19 @@ export default function WatermarkSection({position: watermarkConfig?.position ?? "middle-center",};+ const handleWatermarkToggle = () => {+ const updatedWatermark = !enabled;++ setData({+ ...data,+ enableWatermark: updatedWatermark,+ watermarkConfig: updatedWatermark+ ? watermarkConfig || initialconfig+ : null,+ });+ setEnabled(updatedWatermark);+ };+const handleConfigSave = (config: WatermarkConfig) => {setData({...data,diff --git a/pages/api/links/[id]/index.ts b/pages/api/links/[id]/index.tsindex 4eb7425b..7c24dc89 100644--- a/pages/api/links/[id]/index.ts+++ b/pages/api/links/[id]/index.ts@@ -8,7 +8,7 @@ import {fetchDocumentLinkData,} from "@/lib/api/links/link-data";import prisma from "@/lib/prisma";-import { CustomUser } from "@/lib/types";+import { CustomUser, WatermarkConfigSchema } from "@/lib/types";import {decryptEncrpytedPassword,generateEncrpytedPassword,@@ -274,6 +274,28 @@ export default async function handle(});}+ if (linkData.enableWatermark) {+ if (!linkData.watermarkConfig) {+ return res.status(400).json({+ error:+ "Watermark configuration is required when watermark is enabled.",+ });+ }++ // Validate the watermark config structure+ const validation = WatermarkConfigSchema.safeParse(+ linkData.watermarkConfig,+ );+ if (!validation.success) {+ return res.status(400).json({+ error: "Invalid watermark configuration.",+ details: validation.error.issues+ .map((issue) => issue.message)+ .join(", "),+ });+ }+ }+const updatedLink = await prisma.$transaction(async (tx) => {const link = await tx.link.update({where: { id, teamId },diff --git a/pages/api/links/download/dataroom-document.ts b/pages/api/links/download/dataroom-document.tsindex 3532e2ac..7e86e4e9 100644--- a/pages/api/links/download/dataroom-document.ts+++ b/pages/api/links/download/dataroom-document.ts@@ -199,7 +199,8 @@ export default async function handle(// For PDF files with watermark, always buffer and processif (downloadDocuments[0].document!.versions[0].type === "pdf" &&- view.link.enableWatermark+ view.link.enableWatermark &&+ view.link.watermarkConfig) {const response = await fetch(`${process.env.NEXTAUTH_URL}/api/mupdf/annotate-document`,diff --git a/pages/api/links/index.ts b/pages/api/links/index.tsindex 1a17e724..c503fae7 100644--- a/pages/api/links/index.ts+++ b/pages/api/links/index.ts@@ -6,7 +6,7 @@ import { getServerSession } from "next-auth/next";import { errorhandler } from "@/lib/errorHandler";import prisma from "@/lib/prisma";-import { CustomUser } from "@/lib/types";+import { CustomUser, WatermarkConfigSchema } from "@/lib/types";import {decryptEncrpytedPassword,generateEncrpytedPassword,@@ -123,6 +123,28 @@ export default async function handler(});}+ if (linkData.enableWatermark) {+ if (!linkData.watermarkConfig) {+ return res.status(400).json({+ error:+ "Watermark configuration is required when watermark is enabled.",+ });+ }++ // Validate the watermark config structure+ const validation = WatermarkConfigSchema.safeParse(+ linkData.watermarkConfig,+ );+ if (!validation.success) {+ return res.status(400).json({+ error: "Invalid watermark configuration.",+ details: validation.error.issues+ .map((issue) => issue.message)+ .join(", "),+ });+ }+ }+// Fetch the link and its related document from the databaseconst updatedLink = await prisma.$transaction(async (tx) => {const link = await tx.link.create({