Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
Merge branch 'main' of https://github.com/vndpal/papermark into feat/spam-protection
Vinod Pal5eb8e2874b03
diff --cc components/emails/viewed-document.tsxindex 5be62a51,850e5c66..218bad13--- a/components/emails/viewed-document.tsx+++ b/components/emails/viewed-document.tsx@@@ -77,10 -77,6 +77,10 @@@ export default function ViewedDocument(If you have any feedback or questions about this email, simplyreply to it. I'd love to hear from you!</Text>+ <Text className="text-xs">- To stop email notifications for this link views, edit the link- and uncheck "Receive email notification".++ To stop email notifications for this link, edit the link and++ uncheck "Receive email notification".+ </Text></Section></Container></Body>diff --cc components/links/link-sheet/index.tsxindex 6aa0fc08,13cae173..e63b2889--- a/components/links/link-sheet/index.tsx+++ b/components/links/link-sheet/index.tsx@@@ -23,7 -23,7 +23,8 @@@ import { UpgradePlanModal } from "@/comimport Link from "next/link";import DomainSection from "./domain-section";import AllowDownloadSection from "./allow-download-section";+ import { useTeam } from "@/context/team-context";+import AllowNotificationSection from "./allow-notification";export const DEFAULT_LINK_PROPS = {id: null,@@@ -109,20 -108,24 +111,24 @@@ export default function LinkSheet(setIsOpen(false);// Update the link in the list of linksmutate(- `/api/documents/${encodeURIComponent(documentId)}/links`,+ `/api/teams/${teamInfo?.currentTeam?.id}/documents/${encodeURIComponent(- documentId++ documentId,+ )}/links`,(links || []).map((link) =>-- link.id === currentLink.id ? returnedLink : link++ link.id === currentLink.id ? returnedLink : link,),-- false++ false,);toast.success("Link updated successfully");} else {setIsOpen(false);// Add the new link to the list of linksmutate(- `/api/documents/${encodeURIComponent(documentId)}/links`,+ `/api/teams/${teamInfo?.currentTeam?.id}/documents/${encodeURIComponent(- documentId++ documentId,+ )}/links`,[...(links || []), returnedLink],-- false++ false,);toast.success("Link created successfully");}diff --cc components/links/links-table.tsxindex ce90b801,fcd108a7..9d5621db--- a/components/links/links-table.tsx+++ b/components/links/links-table.tsx@@@ -76,7 -75,7 +78,7 @@@ export default function LinksTable()const handleArchiveLink = async (linkId: string,documentId: string,-- isArchived: boolean++ isArchived: boolean,) => {setIsLoading(true);@@@ -98,15 -97,17 +100,17 @@@// Update the archived link in the list of linksmutate(- `/api/documents/${encodeURIComponent(documentId)}/links`,+ `/api/teams/${teamInfo?.currentTeam?.id}/documents/${encodeURIComponent(- documentId++ documentId,+ )}/links`,(links || []).map((link) => (link.id === linkId ? archivedLink : link)),-- false++ false,);toast.success(!isArchived? "Link successfully archived"-- : "Link successfully reactivated"++ : "Link successfully reactivated",);setIsLoading(false);};@@@ -158,9 -159,8 +162,9 @@@`group/cell flex items-center gap-x-4 rounded-md text-secondary-foreground px-3 py-1 group-hover/row:ring-1 group-hover/row:ring-gray-400 group-hover/row:dark:ring-gray-100 transition-all`,link.domainId && hasFreePlan? "bg-destructive hover:bg-red-700 hover:dark:bg-red-200"-- : "bg-secondary hover:bg-emerald-700 hover:dark:bg-emerald-200"- )}>++ : "bg-secondary hover:bg-emerald-700 hover:dark:bg-emerald-200",+ )}+ ><div className="whitespace-nowrap hidden sm:flex text-sm group-hover/cell:hidden">{link.domainId? `https://${link.domainSlug}/${link.slug}`@@@ -187,15 -186,14 +191,15 @@@link.domainId? () =>handleCopyToClipboard(-- `https://${link.domainSlug}/${link.slug}`++ `https://${link.domainSlug}/${link.slug}`,): () =>handleCopyToClipboard(-- `https://${process.env.NEXT_PUBLIC_ROOT_DOMAIN}/view/${link.id}`++ `https://${process.env.NEXT_PUBLIC_ROOT_DOMAIN}/view/${link.id}`,)}- title="Copy to clipboard">+ title="Copy to clipboard"+ >Copy{" "}<span className="hidden sm:inline-flex">to Clipboard@@@ -222,9 -220,8 +226,9 @@@{link.views[0] ? (<timedateTime={new Date(-- link.views[0].viewedAt- ).toISOString()}>++ link.views[0].viewedAt,+ ).toISOString()}+ >{timeAgo(link.views[0].viewedAt)}</time>) : (@@@ -253,10 -249,9 +257,10 @@@handleArchiveLink(link.id,link.documentId,-- link.isArchived++ link.isArchived,)- }>+ }+ >Archive</DropdownMenuItem></DropdownMenuContent>@@@ -365,9 -359,8 +369,9 @@@{link.views[0] ? (<timedateTime={new Date(-- link.views[0].viewedAt- ).toISOString()}>++ link.views[0].viewedAt,+ ).toISOString()}+ >{timeAgo(link.views[0].viewedAt)}</time>) : (@@@ -399,10 -391,9 +403,10 @@@handleArchiveLink(link.id,link.documentId,-- link.isArchived++ link.isArchived,)- }>+ }+ >Reactivate</DropdownMenuItem></DropdownMenuContent>diff --cc pages/api/links/index.tsindex d80b2048,a9ff3dc3..c03d35a7--- a/pages/api/links/index.ts+++ b/pages/api/links/index.ts@@@ -8,7 -13,7 +13,7 @@@ importexport default async function handler(req: NextApiRequest,-- res: NextApiResponse++ res: NextApiResponse,) {if (req.method === "POST") {const session = await getServerSession(req, res, authOptions);@@@ -18,39 -23,81 +23,82 @@@const { documentId, password, expiresAt, ...linkDomainData } = req.body;- const hashedPassword =- password && password.length > 0 ? await hashPassword(password) : null;- const exat = expiresAt ? new Date(expiresAt) : null;+ const userId = (session.user as CustomUser).id;++ try {+ // check if the the team that own the document has the current user+ await getDocumentWithTeamAndUser({+ docId: documentId,+ userId,+ options: {+ team: {+ select: {+ users: {+ select: {+ userId: true,+ },+ },+ },+ },+ },+ });- let { domain, slug, ...linkData } = linkDomainData;+ const hashedPassword =+ password && password.length > 0 ? await hashPassword(password) : null;+ const exat = expiresAt ? new Date(expiresAt) : null;- // set domain and slug to null if the domain is papermark.io- if (domain && domain === "papermark.io") {- domain = null;- slug = null;- }+ let { domain, slug, ...linkData } = linkDomainData;- let domainObj;+ // set domain and slug to null if the domain is papermark.io+ if (domain && domain === "papermark.io") {+ domain = null;+ slug = null;+ }- if (domain && slug) {- domainObj = await prisma.domain.findUnique({- where: {- slug: domain,- },- });+ let domainObj;- if (!domainObj) {- return res.status(400).json({ error: "Domain not found." });- }+ if (domain && slug) {+ domainObj = await prisma.domain.findUnique({+ where: {+ slug: domain,+ },+ });++ if (!domainObj) {+ return res.status(400).json({ error: "Domain not found." });+ }- // console.log(domainObj);+ // console.log(domainObj);- const existingLink = await prisma.link.findUnique({- where: {- domainSlug_slug: {- slug: slug,- domainSlug: domain,+ const existingLink = await prisma.link.findUnique({+ where: {+ domainSlug_slug: {+ slug: slug,+ domainSlug: domain,+ },},+ });++ if (existingLink) {+ return res.status(400).json({+ error: "The link already exists.",+ });+ }+ }++ // Fetch the link and its related document from the database+ const link = await prisma.link.create({+ data: {+ documentId: documentId,+ password: hashedPassword,+ name: linkData.name || null,+ emailProtected: linkData.emailProtected,+ expiresAt: exat,+ allowDownload: linkData.allowDownload,+ domainId: domainObj?.id || null,+ domainSlug: domain || null,+ slug: slug || null,++ enableNotification: linkData.enableNotification,},});