Skip to content

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

feat: get sheet data from function

Marc Seitz5b0fabe02c29
diff --git a/components/view/document-view.tsx b/components/view/document-view.tsx
index 0c4ef789..eea9a708 100644
--- a/components/view/document-view.tsx
+++ b/components/view/document-view.tsx
@@ -25,6 +25,10 @@ export type DEFAULT_DOCUMENT_VIEW_TYPE = {
pages?:
| { file: string; pageNumber: string; embeddedLinks: string[] }[]
| null;
+ sheetData?: {
+ rowData: { [key: string]: any }[];
+ columnData: string[];
+ } | null;
};
export default function DocumentView({
@@ -98,7 +102,8 @@ export default function DocumentView({
setVerificationRequested(true);
setIsLoading(false);
} else {
- const { viewId, file, pages } = fetchData as DEFAULT_DOCUMENT_VIEW_TYPE;
+ const { viewId, file, pages, sheetData } =
+ fetchData as DEFAULT_DOCUMENT_VIEW_TYPE;
plausible("documentViewed"); // track the event
analytics.identify(
userEmail ?? verifiedEmail ?? data.email ?? undefined,
@@ -109,7 +114,7 @@ export default function DocumentView({
viewerId: viewId,
viewerEmail: data.email || verifiedEmail || userEmail,
});
- setViewData({ viewId, file, pages });
+ setViewData({ viewId, file, pages, sheetData });
setSubmitted(true);
setVerificationRequested(false);
setIsLoading(false);
diff --git a/pages/api/views.ts b/pages/api/views.ts
index 55f6c631..57db9070 100644
--- a/pages/api/views.ts
+++ b/pages/api/views.ts
@@ -5,6 +5,7 @@ import { sendVerificationEmail } from "@/lib/emails/send-email-verification";
import { getFile } from "@/lib/files/get-file";
import { newId } from "@/lib/id-helper";
import prisma from "@/lib/prisma";
+import { parseSheet } from "@/lib/sheet";
import { checkPassword, decryptEncrpytedPassword, log } from "@/lib/utils";
export default async function handle(
@@ -218,6 +219,7 @@ export default async function handle(
// if document version has pages, then return pages
// otherwise, return file from document version
let documentPages, documentVersion;
+ let columnData, rowData;
// let documentPagesPromise, documentVersionPromise;
if (hasPages) {
// get pages from document version
@@ -267,6 +269,17 @@ export default async function handle(
type: documentVersion.storageType,
});
}
+
+ if (documentVersion.type === "xlsx") {
+ const fileUrl = await getFile({
+ data: documentVersion.file,
+ type: documentVersion.storageType,
+ });
+
+ const data = await parseSheet({ fileUrl });
+ columnData = data.columnData;
+ rowData = data.rowData;
+ }
console.timeEnd("get-file");
}
@@ -284,6 +297,10 @@ export default async function handle(
? documentVersion.file
: undefined,
pages: documentPages ? documentPages : undefined,
+ sheetData:
+ documentVersion && documentVersion.type === "xlsx"
+ ? { columnData, rowData }
+ : undefined,
};
return res.status(200).json(returnObject);