Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
feat: add screen protection
Marc Seitz53d8aa875392
diff --git a/components/links/link-sheet/index.tsx b/components/links/link-sheet/index.tsxindex d5e0e796..f166b730 100644--- a/components/links/link-sheet/index.tsx+++ b/components/links/link-sheet/index.tsx@@ -37,6 +37,7 @@ export const DEFAULT_LINK_PROPS = {denyList: [],enableNotification: true,enableFeedback: true,+ enableScreenshotProtection: false,enableCustomMetatag: false,metaTitle: null,metaDescription: null,@@ -60,6 +61,7 @@ export type DEFAULT_LINK_TYPE = {denyList: string[];enableNotification: boolean;enableFeedback: boolean;+ enableScreenshotProtection: boolean;enableCustomMetatag: boolean; // metatagsmetaTitle: string | null; // metatagsmetaDescription: string | null; // metatagsdiff --git a/components/links/link-sheet/link-options.tsx b/components/links/link-sheet/link-options.tsxindex 59de10bb..34b64657 100644--- a/components/links/link-sheet/link-options.tsx+++ b/components/links/link-sheet/link-options.tsx@@ -20,6 +20,7 @@ import FeedbackSection from "@/components/links/link-sheet/feedback-section";import { UpgradePlanModal } from "@/components/billing/upgrade-plan-modal";import { usePlan } from "@/lib/swr/use-billing";import QuestionSection from "./question-section";+import ScreenshotProtectionSection from "./screenshot-protection-section";export const LinkOptions = ({data,@@ -34,10 +35,18 @@ export const LinkOptions = ({const [openUpgradeModal, setOpenUpgradeModal] = useState<boolean>(false);const [trigger, setTrigger] = useState<string>("");+ const [upgradePlan, setUpgradePlan] = useState<"Pro" | "Business">("Pro");- const handleUpgradeStateChange = (state: boolean, trigger: string) => {+ const handleUpgradeStateChange = (+ state: boolean,+ trigger: string,+ plan?: "Pro" | "Business",+ ) => {setOpenUpgradeModal(state);setTrigger(trigger);+ if (plan) {+ setUpgradePlan(plan);+ }};return (@@ -76,6 +85,11 @@ export const LinkOptions = ({handleUpgradeStateChange={handleUpgradeStateChange}/><PasswordSection {...{ data, setData }} />+ <ScreenshotProtectionSection+ {...{ data, setData }}+ hasFreePlan={isNotBusiness}+ handleUpgradeStateChange={handleUpgradeStateChange}+ /><FeedbackSection {...{ data, setData }} /><QuestionSection{...{ data, setData }}@@ -85,9 +99,9 @@ export const LinkOptions = ({</AccordionContent></AccordionItem></Accordion>- {hasFreePlan ? (+ {hasFreePlan || isNotBusiness ? (<UpgradePlanModal- clickedPlan="Pro"+ clickedPlan={upgradePlan}open={openUpgradeModal}setOpen={setOpenUpgradeModal}trigger={trigger}diff --git a/components/links/link-sheet/question-section.tsx b/components/links/link-sheet/question-section.tsxindex 5682f6a7..db45e712 100644--- a/components/links/link-sheet/question-section.tsx+++ b/components/links/link-sheet/question-section.tsx@@ -36,7 +36,11 @@ export default function QuestionSection({data: DEFAULT_LINK_TYPE;setData: Dispatch<SetStateAction<DEFAULT_LINK_TYPE>>;hasFreePlan: boolean;- handleUpgradeStateChange: (state: boolean, trigger: string) => void;+ handleUpgradeStateChange: (+ state: boolean,+ trigger: string,+ plan?: "Pro" | "Business",+ ) => void;}) {const { enableQuestion, questionText, questionType } = data;const [enabled, setEnabled] = useState<boolean>(false);@@ -68,14 +72,15 @@ export default function QuestionSection({handleUpgradeStateChange(true,"link_sheet_question_section",+ "Business",): undefined}>Feedback Question- <span>+ {/* <span><HelpCircleIcon className="text-muted-foreground h-4 w-4" />- </span>+ </span> */}{hasFreePlan && (<span className="bg-background text-foreground ring-1 ring-gray-800 dark:ring-gray-500 rounded-full px-2 py-0.5 text-xs ml-2">Business@@ -88,7 +93,11 @@ export default function QuestionSection({onClick={hasFreePlan? () =>- handleUpgradeStateChange(true, "link_sheet_question_section")+ handleUpgradeStateChange(+ true,+ "link_sheet_question_section",+ "Business",+ ): undefined}className={hasFreePlan ? "opacity-50" : undefined}diff --git a/components/links/link-sheet/screenshot-protection-section.tsx b/components/links/link-sheet/screenshot-protection-section.tsxnew file mode 100644index 00000000..f683a830--- /dev/null+++ b/components/links/link-sheet/screenshot-protection-section.tsx@@ -0,0 +1,86 @@+import { Dispatch, SetStateAction, useState, useEffect } from "react";+import { Switch } from "@/components/ui/switch";+import { cn } from "@/lib/utils";+import { DEFAULT_LINK_TYPE } from ".";++export default function ScreenshotProtectionSection({+ data,+ setData,+ hasFreePlan,+ handleUpgradeStateChange,+}: {+ data: DEFAULT_LINK_TYPE;+ setData: Dispatch<SetStateAction<DEFAULT_LINK_TYPE>>;+ hasFreePlan: boolean;+ handleUpgradeStateChange: (+ state: boolean,+ trigger: string,+ plan?: "Pro" | "Business",+ ) => void;+}) {+ const { enableScreenshotProtection } = data;+ const [enabled, setEnabled] = useState<boolean>(true);++ useEffect(() => {+ setEnabled(enableScreenshotProtection);+ }, [enableScreenshotProtection]);++ const handleEnableScreenshotProtection = () => {+ const updatedEnableScreenshotProtection = !enabled;+ setData({+ ...data,+ enableScreenshotProtection: updatedEnableScreenshotProtection,+ });+ setEnabled(updatedEnableScreenshotProtection);+ };++ return (+ <div className="pb-5">+ <div className="flex items-center justify-between">+ <div className="flex items-center justify-between space-x-2">+ <h2+ className={cn(+ "text-sm font-medium leading-6",+ enabled ? "text-foreground" : "text-muted-foreground",+ hasFreePlan ? "cursor-pointer" : undefined,+ )}+ onClick={+ hasFreePlan+ ? () =>+ handleUpgradeStateChange(+ true,+ "link_sheet_screenshot_protection_section",+ "Business",+ )+ : undefined+ }+ >+ Enable screenshot protection*+ {hasFreePlan && (+ <span className="bg-background text-foreground ring-1 ring-gray-800 dark:ring-gray-500 rounded-full px-2 py-0.5 text-xs ml-2">+ Business+ </span>+ )}+ </h2>+ </div>+ <Switch+ checked={enabled}+ onClick={+ hasFreePlan+ ? () =>+ handleUpgradeStateChange(+ true,+ "link_sheet_screenshot_protection_section",+ "Business",+ )+ : undefined+ }+ className={hasFreePlan ? "opacity-50" : undefined}+ onCheckedChange={+ hasFreePlan ? undefined : handleEnableScreenshotProtection+ }+ />+ </div>+ </div>+ );+}diff --git a/components/links/links-table.tsx b/components/links/links-table.tsxindex 2cca35af..c365c9c4 100644--- a/components/links/links-table.tsx+++ b/components/links/links-table.tsx@@ -81,6 +81,9 @@ export default function LinksTable({? link.enableNotification: false,enableFeedback: link.enableFeedback ? link.enableFeedback : false,+ enableScreenshotProtection: link.enableScreenshotProtection+ ? link.enableScreenshotProtection+ : false,enableCustomMetatag: link.enableCustomMetatag? link.enableCustomMetatag: false,diff --git a/components/view/PagesViewer.tsx b/components/view/PagesViewer.tsxindex 2ae4d7fd..4c2419f7 100644--- a/components/view/PagesViewer.tsx+++ b/components/view/PagesViewer.tsx@@ -10,6 +10,7 @@ import { useRouter } from "next/router";import { PoweredBy } from "./powered-by";import Question from "./question";import { cn } from "@/lib/utils";+import { ScreenProtector } from "./ScreenProtection";const DEFAULT_PRELOADED_IMAGES_NUM = 10;@@ -21,6 +22,7 @@ export default function PagesViewer({assistantEnabled,allowDownload,feedbackEnabled,+ screenshotProtectionEnabled,versionNumber,brand,documentName,@@ -37,6 +39,7 @@ export default function PagesViewer({assistantEnabled?: boolean;allowDownload: boolean;feedbackEnabled: boolean;+ screenshotProtectionEnabled: boolean;versionNumber: number;brand?: Brand | DataroomBrand;documentName?: string;@@ -240,7 +243,7 @@ export default function PagesViewer({{pageNumber <= numPages &&(pages && loadedImages[pageNumber - 1] ? (pages.map((page, index) => {- // contains cloudfront.net in the file path, then use img tag otherwise use next/image+ // served from cloudfront, then use img tag otherwise use next/imageif (page.file.toLowerCase().includes("files.papermark.io")) {return (<img@@ -291,6 +294,7 @@ export default function PagesViewer({{feedbackEnabled && pageNumber !== numPagesWithFeedback ? (<Toolbar viewId={viewId} pageNumber={pageNumber} />) : null}+ {screenshotProtectionEnabled ? <ScreenProtector /> : null}{showPoweredByBanner ? <PoweredBy linkId={linkId} /> : null}</div></>diff --git a/components/view/ScreenProtection.tsx b/components/view/ScreenProtection.tsxnew file mode 100644index 00000000..badad8f5--- /dev/null+++ b/components/view/ScreenProtection.tsx@@ -0,0 +1,24 @@+import { useState } from "react";+import { useHotkeys } from "react-hotkeys-hook";++export const ScreenProtector = () => {+ const [blockScreen, setBlockScreen] = useState<boolean>(false);++ // Key combinations for screenshot in Windows, Linux, and macOS+ useHotkeys(+ "mod+shift+3, mod+shift+4, mod+shift+5, mod+shift+6, alt+printscreen, printscreen, mod+ctrl+shift+3, mod+ctrl+shift+4",+ (event) => {+ setBlockScreen(true);+ // Set timeout to hide the block screen after a delay+ setTimeout(() => {+ setBlockScreen(false);+ }, 500); // Display the white screen for 2 seconds+ event.preventDefault();+ },+ );++ if (blockScreen) {+ return <div className="absolute bg-white inset-0 w-screen h-screen"></div>;+ }+ return null;+};diff --git a/components/view/dataroom/dataroom-view.tsx b/components/view/dataroom/dataroom-view.tsxindex 7be9bd91..daa2367b 100644--- a/components/view/dataroom/dataroom-view.tsx+++ b/components/view/dataroom/dataroom-view.tsx@@ -239,6 +239,7 @@ export default function DataroomView({documentName={documentData.name}allowDownload={link.allowDownload!}feedbackEnabled={link.enableFeedback!}+ screenshotProtectionEnabled={link.enableScreenshotProtection!}versionNumber={documentData.documentVersionNumber}brand={brand}dataroomId={dataroom.id}diff --git a/components/view/view-data.tsx b/components/view/view-data.tsxindex c6c10bbd..1ccb5815 100644--- a/components/view/view-data.tsx+++ b/components/view/view-data.tsx@@ -23,6 +23,7 @@ export default function ViewData({showPoweredByBanner?: boolean;}) {const { document } = link;+return notionData?.recordMap ? (<NotionPagerecordMap={notionData.recordMap}@@ -42,6 +43,7 @@ export default function ViewData({assistantEnabled={document.assistantEnabled}allowDownload={link.allowDownload!}feedbackEnabled={link.enableFeedback!}+ screenshotProtectionEnabled={link.enableScreenshotProtection!}versionNumber={document.versions[0].versionNumber}brand={brand}showPoweredByBanner={showPoweredByBanner}diff --git a/package-lock.json b/package-lock.jsonindex 11dc6f70..99422d8f 100644--- a/package-lock.json+++ b/package-lock.json@@ -87,6 +87,7 @@"react-draggable": "^4.4.6","react-dropzone": "^14.2.3","react-email": "^2.1.1",+ "react-hotkeys-hook": "^4.5.0","react-intersection-observer": "^9.8.2","react-notion-x": "^6.16.0","react-pdf": "^7.7.1",@@ -14664,12 +14665,9 @@"integrity": "sha512-nsO+KSNgo1SbJqJEYRE9ERzo7YtYbou/OqjSQKxV7jcKox7+usiUVZOAC+XnDOABXggQTno0Y1CpVnuWEc1boQ=="},"node_modules/react-hotkeys-hook": {- "version": "3.4.7",- "resolved": "https://registry.npmjs.org/react-hotkeys-hook/-/react-hotkeys-hook-3.4.7.tgz",- "integrity": "sha512-+bbPmhPAl6ns9VkXkNNyxlmCAIyDAcWbB76O4I0ntr3uWCRuIQf/aRLartUahe9chVMPj+OEzzfk3CQSjclUEQ==",- "dependencies": {- "hotkeys-js": "3.9.4"- },+ "version": "4.5.0",+ "resolved": "https://registry.npmjs.org/react-hotkeys-hook/-/react-hotkeys-hook-4.5.0.tgz",+ "integrity": "sha512-Samb85GSgAWFQNvVt3PS90LPPGSf9mkH/r4au81ZP1yOIFayLC3QAvqTgGtJ8YEDMXtPmaVBs6NgipHO6h4Mug==","peerDependencies": {"react": ">=16.8.1","react-dom": ">=16.8.1"@@ -14767,6 +14765,18 @@}}},+ "node_modules/react-notion-x/node_modules/react-hotkeys-hook": {+ "version": "3.4.7",+ "resolved": "https://registry.npmjs.org/react-hotkeys-hook/-/react-hotkeys-hook-3.4.7.tgz",+ "integrity": "sha512-+bbPmhPAl6ns9VkXkNNyxlmCAIyDAcWbB76O4I0ntr3uWCRuIQf/aRLartUahe9chVMPj+OEzzfk3CQSjclUEQ==",+ "dependencies": {+ "hotkeys-js": "3.9.4"+ },+ "peerDependencies": {+ "react": ">=16.8.1",+ "react-dom": ">=16.8.1"+ }+ },"node_modules/react-notion-x/node_modules/react-lazy-images": {"version": "1.1.0","resolved": "https://registry.npmjs.org/react-lazy-images/-/react-lazy-images-1.1.0.tgz",diff --git a/package.json b/package.jsonindex 73703c69..24785a8f 100644--- a/package.json+++ b/package.json@@ -95,6 +95,7 @@"react-draggable": "^4.4.6","react-dropzone": "^14.2.3","react-email": "^2.1.1",+ "react-hotkeys-hook": "^4.5.0","react-intersection-observer": "^9.8.2","react-notion-x": "^6.16.0","react-pdf": "^7.7.1",diff --git a/pages/api/links/[id]/dataroom.ts b/pages/api/links/[id]/dataroom.tsindex 51e74d31..1d74b7e1 100644--- a/pages/api/links/[id]/dataroom.ts+++ b/pages/api/links/[id]/dataroom.ts@@ -29,6 +29,7 @@ export default async function handle(password: true,isArchived: true,enableCustomMetatag: true,+ enableScreenshotProtection: true,metaTitle: true,metaDescription: true,metaImage: true,diff --git a/pages/api/links/[id]/index.ts b/pages/api/links/[id]/index.tsindex 8c191804..23759896 100644--- a/pages/api/links/[id]/index.ts+++ b/pages/api/links/[id]/index.ts@@ -26,6 +26,7 @@ export default async function handle(emailAuthenticated: true,allowDownload: true,enableFeedback: true,+ enableScreenshotProtection: true,password: true,isArchived: true,enableCustomMetatag: true,@@ -184,6 +185,7 @@ export default async function handle(slug: slug || null,enableNotification: linkData.enableNotification,enableFeedback: linkData.enableFeedback,+ enableScreenshotProtection: linkData.enableScreenshotProtection,enableCustomMetatag: linkData.enableCustomMetatag,metaTitle: linkData.metaTitle || null,metaDescription: linkData.metaDescription || null,diff --git a/pages/api/links/domains/[...domainSlug].ts b/pages/api/links/domains/[...domainSlug].tsindex 59c3d5b3..852afbc3 100644--- a/pages/api/links/domains/[...domainSlug].ts+++ b/pages/api/links/domains/[...domainSlug].ts@@ -40,6 +40,7 @@ export default async function handle(isArchived: true,enableCustomMetatag: true,enableFeedback: true,+ enableScreenshotProtection: true,metaTitle: true,metaDescription: true,metaImage: true,diff --git a/pages/api/links/index.ts b/pages/api/links/index.tsindex 9fbc346d..165d399b 100644--- a/pages/api/links/index.ts+++ b/pages/api/links/index.ts@@ -127,6 +127,7 @@ export default async function handler(slug: slug || null,enableNotification: linkData.enableNotification,enableFeedback: linkData.enableFeedback,+ enableScreenshotProtection: linkData.enableScreenshotProtection,enableCustomMetatag: linkData.enableCustomMetatag,metaTitle: linkData.metaTitle || null,metaDescription: linkData.metaDescription || null,diff --git a/prisma/migrations/20240424152839_add_screenprotection_to_link/migration.sql b/prisma/migrations/20240424152839_add_screenprotection_to_link/migration.sqlnew file mode 100644index 00000000..29ca7177--- /dev/null+++ b/prisma/migrations/20240424152839_add_screenprotection_to_link/migration.sql@@ -0,0 +1,2 @@+-- AlterTable+ALTER TABLE "Link" ADD COLUMN "enableScreenshotProtection" BOOLEAN DEFAULT false;diff --git a/prisma/schema.prisma b/prisma/schema.prismaindex 372a9df6..c2b87405 100644--- a/prisma/schema.prisma+++ b/prisma/schema.prisma@@ -192,33 +192,34 @@ enum LinkType {}model Link {- id String @id @default(cuid())- document Document? @relation(fields: [documentId], references: [id], onDelete: Cascade)- documentId String? // This can be nullable, representing links without documents- dataroom Dataroom? @relation(fields: [dataroomId], references: [id], onDelete: Cascade)- dataroomId String? // This can be nullable, representing links without datarooms- linkType LinkType @default(DOCUMENT_LINK)- url String? @unique- name String? // Link name- slug String? // Link slug for pretty URLs- expiresAt DateTime? // Optional expiration date- password String? // Optional password for link protection- allowList String[] // Array of emails and domains allowed to view the document- denyList String[] // Array of emails and domains denied to view the document- emailProtected Boolean @default(true) // Optional email protection- emailAuthenticated Boolean @default(false) // Optional email authentication flag- allowDownload Boolean? @default(false) // Optional give user a option to allow to download the document- isArchived Boolean @default(false) // Indicates if the link is archived- views View[]- domain Domain? @relation(fields: [domainId], references: [id], onDelete: SetNull)- domainId String? // This can be nullable, representing links without custom domains- domainSlug String? // This will store the domain's slug even if the domain is deleted- createdAt DateTime @default(now())- updatedAt DateTime @updatedAt- enableNotification Boolean? @default(true) // Optional give user a option to pause/resume the notifications- enableFeedback Boolean? @default(true) // Optional give user a option to enable the reactions toolbar- enableQuestion Boolean? @default(false) // Optional give user a option to enable the question feedback- feedback Feedback?+ id String @id @default(cuid())+ document Document? @relation(fields: [documentId], references: [id], onDelete: Cascade)+ documentId String? // This can be nullable, representing links without documents+ dataroom Dataroom? @relation(fields: [dataroomId], references: [id], onDelete: Cascade)+ dataroomId String? // This can be nullable, representing links without datarooms+ linkType LinkType @default(DOCUMENT_LINK)+ url String? @unique+ name String? // Link name+ slug String? // Link slug for pretty URLs+ expiresAt DateTime? // Optional expiration date+ password String? // Optional password for link protection+ allowList String[] // Array of emails and domains allowed to view the document+ denyList String[] // Array of emails and domains denied to view the document+ emailProtected Boolean @default(true) // Optional email protection+ emailAuthenticated Boolean @default(false) // Optional email authentication flag+ allowDownload Boolean? @default(false) // Optional give user a option to allow to download the document+ isArchived Boolean @default(false) // Indicates if the link is archived+ views View[]+ domain Domain? @relation(fields: [domainId], references: [id], onDelete: SetNull)+ domainId String? // This can be nullable, representing links without custom domains+ domainSlug String? // This will store the domain's slug even if the domain is deleted+ createdAt DateTime @default(now())+ updatedAt DateTime @updatedAt+ enableNotification Boolean? @default(true) // Optional give user a option to pause/resume the notifications+ enableFeedback Boolean? @default(true) // Optional give user a option to enable the reactions toolbar+ enableQuestion Boolean? @default(false) // Optional give user a option to enable the question feedback+ enableScreenshotProtection Boolean? @default(false) // Optional give user a option to enable the screenshot protection+ feedback Feedback?// custom metatagsmetaTitle String? // This will be the meta title of the link