Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
fix: bulk download
Marc Seitzd99a540e1490
diff --git a/package-lock.json b/package-lock.jsonindex 6d01ff96..d0a0b680 100644--- a/package-lock.json+++ b/package-lock.json@@ -17121,6 +17121,21 @@"peerDependencies": {"zod": "^3.18.0"}+ },+ "node_modules/react-email/node_modules/@next/swc-win32-ia32-msvc": {+ "version": "14.2.29",+ "resolved": "https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-14.2.29.tgz",+ "integrity": "sha512-vkcriFROT4wsTdSeIzbxaZjTNTFKjSYmLd8q/GVH3Dn8JmYjUKOuKXHK8n+lovW/kdcpIvydO5GtN+It2CvKWA==",+ "cpu": [+ "ia32"+ ],+ "optional": true,+ "os": [+ "win32"+ ],+ "engines": {+ "node": ">= 10"+ }}}}diff --git a/pages/api/links/download/bulk.ts b/pages/api/links/download/bulk.tsindex d785962f..7d4e1214 100644--- a/pages/api/links/download/bulk.ts+++ b/pages/api/links/download/bulk.ts@@ -5,6 +5,7 @@ import { ItemType, ViewType } from "@prisma/client";import { getLambdaClient } from "@/lib/files/aws-client";import prisma from "@/lib/prisma";+import { getIpAddress } from "@/lib/utils/ip";export const config = {maxDuration: 180,@@ -29,11 +30,15 @@ export default async function handle(select: {id: true,viewedAt: true,+ viewerEmail: true,link: {select: {allowDownload: true,expiresAt: true,isArchived: true,+ enableWatermark: true,+ watermarkConfig: true,+ name: true,},},groupId: true,@@ -61,6 +66,7 @@ export default async function handle(storageType: true,originalFile: true,contentType: true,+ numPages: true,},take: 1,},@@ -148,7 +154,13 @@ export default async function handle([key: string]: {name: string;path: string;- files: { name: string; key: string }[];+ files: {+ name: string;+ key: string;+ type?: string;+ numPages?: number;+ needsWatermark?: boolean;+ }[];};} = {};const fileKeys: string[] = [];@@ -165,6 +177,8 @@ export default async function handle(path: string,fileName: string,fileKey: string,+ fileType?: string,+ numPages?: number,) => {const pathParts = path.split("/").filter(Boolean);let currentPath = "";@@ -191,7 +205,18 @@ export default async function handle(files: [],};}- folderStructure[path].files.push({ name: fileName, key: fileKey });++ const needsWatermark =+ view.link.enableWatermark &&+ (fileType === "pdf" || fileType === "image");++ folderStructure[path].files.push({+ name: fileName,+ key: fileKey,+ type: fileType,+ numPages: numPages,+ needsWatermark: needsWatermark ?? undefined,+ });fileKeys.push(fileKey);};@@ -200,14 +225,21 @@ export default async function handle(.filter((doc) => !doc.folderId).filter((doc) => doc.document.versions[0].type !== "notion").filter((doc) => doc.document.versions[0].storageType !== "VERCEL_BLOB")- .forEach((doc) =>+ .forEach((doc) => {+ const fileKey =+ view.link.enableWatermark && doc.document.versions[0].type === "pdf"+ ? doc.document.versions[0].file+ : (doc.document.versions[0].originalFile ??+ doc.document.versions[0].file);+addFileToStructure("/",doc.document.name,- doc.document.versions[0].originalFile ??- doc.document.versions[0].file,- ),- );+ fileKey,+ doc.document.versions[0].type ?? undefined,+ doc.document.versions[0].numPages ?? undefined,+ );+ });// Add documents in foldersdownloadFolders.forEach((folder) => {@@ -219,14 +251,23 @@ export default async function handle();folderDocs &&- folderDocs.forEach((doc) =>+ folderDocs.forEach((doc) => {+ // Use .file if watermark is enabled and document is PDF, otherwise use .originalFile+ const fileKey =+ view.link.enableWatermark &&+ doc.document.versions[0].type === "pdf"+ ? doc.document.versions[0].file+ : (doc.document.versions[0].originalFile ??+ doc.document.versions[0].file);+addFileToStructure(folder.path,doc.document.name,- doc.document.versions[0].originalFile ??- doc.document.versions[0].file,- ),- );+ fileKey,+ doc.document.versions[0].type ?? undefined,+ doc.document.versions[0].numPages ?? undefined,+ );+ });// If the folder is empty, ensure it's still added to the structureif (folderDocs && folderDocs.length === 0) {@@ -247,6 +288,19 @@ export default async function handle(sourceBucket: process.env.NEXT_PRIVATE_UPLOAD_BUCKET,fileKeys: fileKeys,folderStructure: folderStructure,+ watermarkConfig: view.link.enableWatermark+ ? {+ enabled: true,+ config: view.link.watermarkConfig,+ viewerData: {+ email: view.viewerEmail,+ date: new Date(view.viewedAt).toLocaleDateString(),+ time: new Date(view.viewedAt).toLocaleTimeString(),+ link: view.link.name,+ ipAddress: getIpAddress(req.headers),+ },+ }+ : { enabled: false },}),};