Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
feat: update index generator
Marc Seitzc91ea9bcf622
diff --git a/lib/dataroom/index-generator.ts b/lib/dataroom/index-generator.tsindex b3fef681..bc7f1b39 100644--- a/lib/dataroom/index-generator.ts+++ b/lib/dataroom/index-generator.ts@@ -11,6 +11,7 @@ import {interface GenerateIndexOptions {format?: IndexFileFormat;baseUrl?: string;+ showHierarchicalIndex?: boolean;}interface DataroomDocumentWithVersion {@@ -19,6 +20,7 @@ interface DataroomDocumentWithVersion {orderIndex: number | null;updatedAt: Date;createdAt: Date;+ hierarchicalIndex: string | null;document: {id: string;name: string;@@ -48,7 +50,7 @@ export async function generateDataroomIndex(link: LinkWithDataroom,options: GenerateIndexOptions = {},): Promise<{ data: Buffer; filename: string; mimeType: string }> {- const { format = "excel", baseUrl } = options;+ const { format = "excel", baseUrl, showHierarchicalIndex = false } = options;// Generate the index data structureconst indexData: DataroomIndex = {@@ -74,6 +76,9 @@ export async function generateDataroomIndex(// Add folder entryentries.push({+ hierarchicalIndex: showHierarchicalIndex+ ? folder.hierarchicalIndex+ : undefined,name: folder.name,type: "Folder",path: currentPath.split("/").slice(0, -1).join("/") || "/",@@ -91,6 +96,9 @@ export async function generateDataroomIndex(const latestVersion =doc.document.versions[doc.document.versions.length - 1];const entry: DataroomIndexEntry = {+ hierarchicalIndex: showHierarchicalIndex+ ? doc.hierarchicalIndex+ : undefined,name: doc.document.name,type: "File",path: `${currentPath}/`,@@ -128,6 +136,7 @@ export async function generateDataroomIndex(// Add root dataroom entryindexData.entries.push({+ hierarchicalIndex: showHierarchicalIndex ? "0" : undefined,name: link.dataroom.name,type: "Root Folder",path: "",@@ -146,6 +155,9 @@ export async function generateDataroomIndex(const latestVersion =doc.document.versions[doc.document.versions.length - 1];indexData.entries.push({+ hierarchicalIndex: showHierarchicalIndex+ ? doc.hierarchicalIndex+ : undefined,name: doc.document.name,type: "File",path: "/",@@ -180,8 +192,11 @@ export async function generateDataroomIndex(const workbook = new ExcelJS.Workbook();const worksheet = workbook.addWorksheet("Dataroom Index");- // Set column widths and properties- worksheet.columns = [+ // Define columns with their configuration+ const columns = [+ ...(showHierarchicalIndex+ ? [{ header: "Index", key: "hierarchicalIndex", width: 10 }]+ : []),{ header: "Name", key: "name", width: 30 },{ header: "Type", key: "type", width: 10 },{ header: "Path", key: "path", width: 40 },@@ -194,6 +209,18 @@ export async function generateDataroomIndex({ header: "Last Updated At", key: "lastUpdated", width: 20 },];+ // Set column widths and properties+ worksheet.columns = columns;++ // Find the index of the onlineUrl column (1-based for ExcelJS)+ const onlineUrlColumnIndex =+ columns.findIndex((col) => col.key === "onlineUrl") + 1;++ // Validate that the column was found+ if (onlineUrlColumnIndex === 0) {+ throw new Error("onlineUrl column not found in column definitions");+ }+// Add title rowsworksheet.spliceRows(1,@@ -250,6 +277,7 @@ export async function generateDataroomIndex(// Add data rowsindexData.entries.forEach((entry, index) => {const row = worksheet.addRow([+ ...(showHierarchicalIndex ? [entry.hierarchicalIndex] : []),entry.name,entry.type,entry.path,@@ -273,7 +301,7 @@ export async function generateDataroomIndex(// Add hyperlink to Online URLif (entry.onlineUrl) {- const cell = row.getCell(7); // online link column+ const cell = row.getCell(onlineUrlColumnIndex); // dynamically found online link columncell.value = {text: entry.onlineUrl,hyperlink: entry.onlineUrl,@@ -325,6 +353,7 @@ export async function generateDataroomIndex(case "csv": {const csvRows = [[+ ...(showHierarchicalIndex ? ["Index"] : []),"Name","Type","Path",@@ -337,6 +366,7 @@ export async function generateDataroomIndex("Last Updated At",],...indexData.entries.map((entry) => [+ ...(showHierarchicalIndex ? [entry.hierarchicalIndex] : []),entry.name,entry.type,entry.path,diff --git a/lib/types/index-file.ts b/lib/types/index-file.tsindex 62d1910e..d2ca9738 100644--- a/lib/types/index-file.ts+++ b/lib/types/index-file.ts@@ -1,4 +1,5 @@export interface DataroomIndexEntry {+ hierarchicalIndex: string | null | undefined;name: string;type: "File" | "Folder" | "Root Folder";path: string;diff --git a/pages/api/links/generate-index.ts b/pages/api/links/generate-index.tsindex 67636bc5..bb579f62 100644--- a/pages/api/links/generate-index.ts+++ b/pages/api/links/generate-index.ts@@ -3,6 +3,7 @@ import { NextApiRequest, NextApiResponse } from "next";import { ItemType } from "@prisma/client";import { generateDataroomIndex } from "@/lib/dataroom/index-generator";+import { getFeatureFlags } from "@/lib/featureFlags";import prisma from "@/lib/prisma";import { LinkWithDataroom } from "@/lib/types";import { IndexFileFormat } from "@/lib/types/index-file";@@ -185,6 +186,7 @@ export default async function handle(orderIndex: doc.orderIndex,updatedAt: doc.updatedAt,createdAt: doc.createdAt,+ hierarchicalIndex: doc.hierarchicalIndex,document: {id: doc.document.id,name: doc.document.name,@@ -207,6 +209,10 @@ export default async function handle(},};+ const { dataroomIndex } = await getFeatureFlags({+ teamId: link.dataroom.teamId,+ });+// Generate the index file using the appropriate generatorconst { data, filename, mimeType } = await generateDataroomIndex(linkWithDataroom,@@ -215,6 +221,7 @@ export default async function handle(baseUrl: link.domainId? `${link.domainSlug}/${link.slug}`: `${process.env.NEXT_PUBLIC_MARKETING_URL}/view/${link.id}`,+ showHierarchicalIndex: dataroomIndex,},);diff --git a/pages/api/teams/[teamId]/datarooms/[id]/generate-index.ts b/pages/api/teams/[teamId]/datarooms/[id]/generate-index.tsindex 484bee11..9d3fdfd1 100644--- a/pages/api/teams/[teamId]/datarooms/[id]/generate-index.ts+++ b/pages/api/teams/[teamId]/datarooms/[id]/generate-index.ts@@ -5,6 +5,7 @@ import { ItemType } from "@prisma/client";import { getServerSession } from "next-auth/next";import { generateDataroomIndex } from "@/lib/dataroom/index-generator";+import { getFeatureFlags } from "@/lib/featureFlags";import prisma from "@/lib/prisma";import { CustomUser, LinkWithDataroom } from "@/lib/types";import { IndexFileFormat } from "@/lib/types/index-file";@@ -183,6 +184,7 @@ export default async function handle(orderIndex: doc.orderIndex,updatedAt: doc.updatedAt,createdAt: doc.createdAt,+ hierarchicalIndex: doc.hierarchicalIndex,document: {id: doc.document.id,name: doc.document.name,@@ -205,6 +207,12 @@ export default async function handle(},};+ const { dataroomIndex } = await getFeatureFlags({+ teamId: link.dataroom.teamId,+ });++ console.log("dataroomIndex", dataroomIndex);+// Generate the index file using the appropriate generatorconst { data, filename, mimeType } = await generateDataroomIndex(linkWithDataroom,@@ -213,6 +221,7 @@ export default async function handle(baseUrl: link.domainId? `${link.domainSlug}/${link.slug}`: `${process.env.NEXT_PUBLIC_MARKETING_URL}/view/${link.id}`,+ showHierarchicalIndex: dataroomIndex,},);