Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
feat: add fileSize to documentVersion
Marc Seitz284579289362
diff --git a/components/documents/add-document-modal.tsx b/components/documents/add-document-modal.tsxindex 9732f126..9bd36176 100644--- a/components/documents/add-document-modal.tsx+++ b/components/documents/add-document-modal.tsx@@ -110,7 +110,7 @@ export function AddDocumentModal({return;}- const { type, data, numPages } = await putFile({+ const { type, data, numPages, fileSize } = await putFile({file: currentFile,teamId,});@@ -121,6 +121,7 @@ export function AddDocumentModal({storageType: type!,contentType: contentType,supportedFileType: supportedFileType,+ fileSize: fileSize,};let response: Response | undefined;// create a document or new version in the databasediff --git a/lib/documents/create-document.ts b/lib/documents/create-document.tsindex c0a37963..1af7c194 100644--- a/lib/documents/create-document.ts+++ b/lib/documents/create-document.ts@@ -6,6 +6,7 @@ export type DocumentData = {storageType: DocumentStorageType;contentType: string; // actual file mime typesupportedFileType: string; // papermark types: "pdf", "sheet", "docs", "slides"+ fileSize: number | undefined; // file size in bytes};export const createDocument = async ({@@ -41,6 +42,7 @@ export const createDocument = async ({type: documentData.supportedFileType,contentType: documentData.contentType,createLink: createLink,+ fileSize: documentData.fileSize,}),},);@@ -112,6 +114,7 @@ export const createNewDocumentVersion = async ({numPages: numPages,type: documentData.supportedFileType,contentType: documentData.contentType,+ fileSize: documentData.fileSize,}),},);diff --git a/lib/files/put-file.ts b/lib/files/put-file.tsindex c35aafd0..999ea60d 100644--- a/lib/files/put-file.ts+++ b/lib/files/put-file.ts@@ -18,10 +18,17 @@ export const putFile = async ({file: File;teamId: string;docId?: string;-}) => {+}): Promise<{+ type: DocumentStorageType | null;+ data: string | null;+ numPages: number | undefined;+ fileSize: number | undefined;+}> => {const NEXT_PUBLIC_UPLOAD_TRANSPORT = process.env.NEXT_PUBLIC_UPLOAD_TRANSPORT;- const { type, data, numPages } = await match(NEXT_PUBLIC_UPLOAD_TRANSPORT)+ const { type, data, numPages, fileSize } = await match(+ NEXT_PUBLIC_UPLOAD_TRANSPORT,+ ).with("s3", async () => putFileInS3({ file, teamId, docId })).with("vercel", async () => putFileInVercel(file)).otherwise(() => {@@ -29,10 +36,11 @@ export const putFile = async ({type: null,data: null,numPages: undefined,+ fileSize: undefined,};});- return { type, data, numPages };+ return { type, data, numPages, fileSize };};const putFileInVercel = async (file: File) => {@@ -51,6 +59,7 @@ const putFileInVercel = async (file: File) => {type: DocumentStorageType.VERCEL_BLOB,data: newBlob.url,numPages: numPages,+ fileSize: file.size,};};@@ -73,7 +82,7 @@ const putFileInS3 = async ({!file.name.endsWith(".dxf")) {throw new Error(- "Only PDF, Powerpoint, Word, and Excel files are supported",+ "Only PDF, Powerpoint, Word, and Excel, ZIP files are supported",);}@@ -137,5 +146,6 @@ const putFileInS3 = async ({type: DocumentStorageType.S3_PATH,data: key,numPages: numPages,+ fileSize: file.size,};};diff --git a/pages/api/teams/[teamId]/documents/[id]/versions/index.ts b/pages/api/teams/[teamId]/documents/[id]/versions/index.tsindex df0d345e..dac96d00 100644--- a/pages/api/teams/[teamId]/documents/[id]/versions/index.ts+++ b/pages/api/teams/[teamId]/documents/[id]/versions/index.ts@@ -28,13 +28,15 @@ export default async function handle(teamId: string;id: string;};- const { url, type, numPages, storageType, contentType } = req.body as {- url: string;- type: string;- numPages: number;- storageType: DocumentStorageType;- contentType: string;- };+ const { url, type, numPages, storageType, contentType, fileSize } =+ req.body as {+ url: string;+ type: string;+ numPages: number;+ storageType: DocumentStorageType;+ contentType: string;+ fileSize: number | undefined;+ };const userId = (session.user as CustomUser).id;@@ -72,6 +74,7 @@ export default async function handle(isPrimary: true,versionNumber: currentVersionNumber + 1,contentType,+ fileSize,},});diff --git a/pages/api/teams/[teamId]/documents/index.ts b/pages/api/teams/[teamId]/documents/index.tsindex 19cd8bf2..702f4f57 100644--- a/pages/api/teams/[teamId]/documents/index.ts+++ b/pages/api/teams/[teamId]/documents/index.ts@@ -169,6 +169,7 @@ export default async function handle(folderPathName,contentType,createLink,+ fileSize,} = req.body as {name: string;url: string;@@ -178,6 +179,7 @@ export default async function handle(folderPathName?: string;contentType: string;createLink?: boolean;+ fileSize?: number;};try {@@ -250,6 +252,7 @@ export default async function handle(numPages: numPages,isPrimary: true,versionNumber: 1,+ fileSize: fileSize,},},folderId: folder?.id ? folder.id : null,diff --git a/prisma/migrations/20241118000000_add_filesize_and_downloadonly/migration.sql b/prisma/migrations/20241118000000_add_filesize_and_downloadonly/migration.sqlindex 13206f80..7100f06f 100644--- a/prisma/migrations/20241118000000_add_filesize_and_downloadonly/migration.sql+++ b/prisma/migrations/20241118000000_add_filesize_and_downloadonly/migration.sql@@ -1,3 +1,6 @@-- AlterTableALTER TABLE "Document" ADD COLUMN "downloadOnly" BOOLEAN NOT NULL DEFAULT false;+-- AlterTable+ALTER TABLE "DocumentVersion" ADD COLUMN "fileSize" INTEGER;+diff --git a/prisma/schema.prisma b/prisma/schema.prismaindex 6e29eb51..c36f8cf5 100644--- a/prisma/schema.prisma+++ b/prisma/schema.prisma@@ -175,6 +175,7 @@ model DocumentVersion {originalFile String? // This should be a reference to the original file like pptx, xlsx, etc. (S3, Google Cloud Storage, etc.)type String? // This should be a reference to the file type (pdf, docx, etc.)contentType String? // This should be the actual contentType of the file like application/pdf, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, etc.+ fileSize Int? // This should be the size of the file in bytesstorageType DocumentStorageType @default(VERCEL_BLOB)numPages Int? // This should be a reference to the number of pages in the documentisPrimary Boolean @default(false) // Indicates if this is the primary version