Skip to content

Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.

fix: revert changes to api/links

Marc Seitz5a3b66073344
diff --git a/pages/api/links/index.ts b/pages/api/links/index.ts
index ae792b42..dfd40c4b 100644
--- a/pages/api/links/index.ts
+++ b/pages/api/links/index.ts
@@ -53,7 +53,6 @@ export default async function handler(
}
if (dataroomLink) {
- console.log("Creating dataroom link for dataroomId:", targetId);
const dataroom = await prisma.dataroom.findUnique({
where: {
id: targetId,
@@ -69,11 +68,8 @@ export default async function handler(
});
if (!dataroom) {
- console.error("Dataroom not found for id:", targetId);
return res.status(400).json({ error: "Dataroom not found." });
}
-
- console.log("Dataroom found:", dataroom);
}
const hashedPassword =
@@ -126,67 +122,64 @@ export default async function handler(
}
// Fetch the link and its related document from the database
- console.log("Creating link with data:", {
- dataroomId: dataroomLink ? targetId : undefined,
- linkType,
- // ... other link properties
- });
-
const link = await prisma.link.create({
data: {
+ documentId: documentLink ? targetId : null,
+ dataroomId: dataroomLink ? targetId : null,
linkType,
password: hashedPassword,
- name: linkDomainData.name || null,
- emailProtected: linkDomainData.emailProtected,
- emailAuthenticated: linkDomainData.emailAuthenticated,
+ name: linkData.name || null,
+ emailProtected: linkData.emailProtected,
+ emailAuthenticated: linkData.emailAuthenticated,
expiresAt: exat,
- allowDownload: linkDomainData.allowDownload,
+ allowDownload: linkData.allowDownload,
+ domainId: domainObj?.id || null,
domainSlug: domain || null,
slug: slug || null,
- enableNotification: linkDomainData.enableNotification,
- enableFeedback: linkDomainData.enableFeedback,
- enableScreenshotProtection: linkDomainData.enableScreenshotProtection,
- enableCustomMetatag: linkDomainData.enableCustomMetatag,
- metaTitle: linkDomainData.metaTitle || null,
- metaDescription: linkDomainData.metaDescription || null,
- metaImage: linkDomainData.metaImage || null,
- allowList: linkDomainData.allowList,
- denyList: linkDomainData.denyList,
- ...(dataroomLink
- ? {
- dataroom: {
- connect: { id: targetId },
- },
- }
- : {}),
- ...(documentLink
- ? {
- document: {
- connect: { id: targetId },
- },
- }
- : {}),
- ...(domainObj
- ? {
- domain: {
- connect: { id: domainObj.id },
+ enableNotification: linkData.enableNotification,
+ enableFeedback: linkData.enableFeedback,
+ enableScreenshotProtection: linkData.enableScreenshotProtection,
+ enableCustomMetatag: linkData.enableCustomMetatag,
+ metaTitle: linkData.metaTitle || null,
+ metaDescription: linkData.metaDescription || null,
+ metaImage: linkData.metaImage || null,
+ allowList: linkData.allowList,
+ denyList: linkData.denyList,
+ ...(linkData.enableQuestion && {
+ enableQuestion: linkData.enableQuestion,
+ feedback: {
+ create: {
+ data: {
+ question: linkData.questionText,
+ type: linkData.questionType,
},
- }
- : {}),
+ },
+ },
+ }),
+ ...(linkData.enableAgreement && {
+ enableAgreement: linkData.enableAgreement,
+ agreementId: linkData.agreementId,
+ }),
+ ...(linkData.enableWatermark && {
+ enableWatermark: linkData.enableWatermark,
+ watermarkConfig: linkData.watermarkConfig,
+ }),
+ showBanner: linkData.showBanner,
},
});
- console.log("Link created:", link);
-
const linkWithView = {
...link,
_count: { views: 0 },
views: [],
};
+ if (!linkWithView) {
+ return res.status(404).json({ error: "Link not found" });
+ }
+
return res.status(200).json(linkWithView);
} catch (error) {
- console.error("Error creating link:", error);
errorhandler(error, res);
}
}