Skip to content

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

feat: include Index column in downloaded data room index files

Marc Seitz02321f6c7fc6
diff --git a/pages/api/links/generate-index.ts b/pages/api/links/generate-index.ts
index e107df91..ec57a434 100644
--- a/pages/api/links/generate-index.ts
+++ b/pages/api/links/generate-index.ts
@@ -2,10 +2,12 @@ import { NextApiRequest, NextApiResponse } from "next";
import { ItemType } from "@prisma/client";
-import { generateDataroomIndex } from "@/lib/dataroom/index-generator";
-import { getFeatureFlags } from "@/lib/featureFlags";
+import {
+ DataroomIndexSource,
+ generateDataroomIndex,
+} from "@/lib/dataroom/index-generator";
+import { resolveDataroomIndexEnabledForViewer } from "@/lib/featureFlags/dataroom-index-viewer";
import prisma from "@/lib/prisma";
-import { LinkWithDataroom } from "@/lib/types";
import { IndexFileFormat } from "@/lib/types/index-file";
export default async function handle(
@@ -66,6 +68,7 @@ export default async function handle(
id: true,
name: true,
teamId: true,
+ team: { select: { plan: true } },
documents: {
include: {
document: {
@@ -177,14 +180,14 @@ export default async function handle(
);
}
- // Map updatedAt to lastUpdatedAt for the dataroom and transform document versions
- // @ts-ignore
- const linkWithDataroom: LinkWithDataroom = {
- ...link,
+ const linkWithDataroom: DataroomIndexSource = {
+ id: link.id,
dataroom: {
- ...link.dataroom,
+ id: link.dataroom.id,
+ name: link.dataroom.name,
createdAt: link.dataroom.createdAt,
lastUpdatedAt: link.dataroom.updatedAt,
+ folders: link.dataroom.folders,
documents: link.dataroom.documents.map((doc) => ({
id: doc.id,
folderId: doc.folderId,
@@ -202,20 +205,18 @@ export default async function handle(
hasPages: version.hasPages,
file: version.file,
isVertical: version.isVertical,
- numPages: version.numPages,
+ numPages: version.numPages ?? 0,
updatedAt: version.updatedAt,
- fileSize:
- typeof version.fileSize === "bigint"
- ? Number(version.fileSize)
- : version.fileSize,
+ fileSize: Number(version.fileSize ?? 0),
})),
},
})),
},
};
- const { dataroomIndex } = await getFeatureFlags({
+ const showHierarchicalIndex = await resolveDataroomIndexEnabledForViewer({
teamId: link.dataroom.teamId,
+ teamPlan: link.dataroom.team.plan,
});
// Generate the index file using the appropriate generator
@@ -226,7 +227,7 @@ export default async function handle(
baseUrl: link.domainId
? `${link.domainSlug}/${link.slug}`
: `${process.env.NEXT_PUBLIC_MARKETING_URL}/view/${link.id}`,
- showHierarchicalIndex: dataroomIndex,
+ showHierarchicalIndex,
},
);
diff --git a/pages/api/teams/[teamId]/datarooms/[id]/generate-index.ts b/pages/api/teams/[teamId]/datarooms/[id]/generate-index.ts
index 5a448971..d84b8b80 100644
--- a/pages/api/teams/[teamId]/datarooms/[id]/generate-index.ts
+++ b/pages/api/teams/[teamId]/datarooms/[id]/generate-index.ts
@@ -4,10 +4,13 @@ import { authOptions } from "@/pages/api/auth/[...nextauth]";
import { ItemType } from "@prisma/client";
import { getServerSession } from "next-auth/next";
-import { generateDataroomIndex } from "@/lib/dataroom/index-generator";
-import { getFeatureFlags } from "@/lib/featureFlags";
+import {
+ DataroomIndexSource,
+ generateDataroomIndex,
+} from "@/lib/dataroom/index-generator";
+import { resolveDataroomIndexEnabledForViewer } from "@/lib/featureFlags/dataroom-index-viewer";
import prisma from "@/lib/prisma";
-import { CustomUser, LinkWithDataroom } from "@/lib/types";
+import { CustomUser } from "@/lib/types";
import { IndexFileFormat } from "@/lib/types/index-file";
export default async function handle(
@@ -176,14 +179,14 @@ export default async function handle(
);
}
- // Map updatedAt to lastUpdatedAt for the dataroom and transform document versions
- // @ts-ignore
- const linkWithDataroom: LinkWithDataroom = {
- ...link,
+ const linkWithDataroom: DataroomIndexSource = {
+ id: link.id,
dataroom: {
- ...link.dataroom,
+ id: link.dataroom.id,
+ name: link.dataroom.name,
createdAt: link.dataroom.createdAt,
lastUpdatedAt: link.dataroom.updatedAt,
+ folders: link.dataroom.folders,
documents: link.dataroom.documents.map((doc) => ({
id: doc.id,
folderId: doc.folderId,
@@ -201,20 +204,18 @@ export default async function handle(
hasPages: version.hasPages,
file: version.file,
isVertical: version.isVertical,
- numPages: version.numPages,
+ numPages: version.numPages ?? 0,
updatedAt: version.updatedAt,
- fileSize:
- typeof version.fileSize === "bigint"
- ? Number(version.fileSize)
- : version.fileSize,
+ fileSize: Number(version.fileSize ?? 0),
})),
},
})),
},
};
- const { dataroomIndex } = await getFeatureFlags({
+ const showHierarchicalIndex = await resolveDataroomIndexEnabledForViewer({
teamId: link.dataroom.teamId,
+ teamPlan: team.plan,
});
// Generate the index file using the appropriate generator
@@ -225,7 +226,7 @@ export default async function handle(
baseUrl: link.domainId
? `${link.domainSlug}/${link.slug}`
: `${process.env.NEXT_PUBLIC_MARKETING_URL}/view/${link.id}`,
- showHierarchicalIndex: dataroomIndex,
+ showHierarchicalIndex,
},
);
diff --git a/tsconfig.json b/tsconfig.json
index 2f7badaf..c8ec46da 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -31,5 +31,5 @@
".next/types/**/*.ts",
"trigger.config.ts"
],
- "exclude": ["node_modules", "scripts"]
+ "exclude": ["node_modules", "scripts", "**/*.verify.ts"]
}