Skip to content

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

refactor: send less data to client from /api/views

Marc Seitz431fea81e53a
diff --git a/components/view/document-view.tsx b/components/view/document-view.tsx
index c194c88a..0c4ef789 100644
--- a/components/view/document-view.tsx
+++ b/components/view/document-view.tsx
@@ -21,8 +21,10 @@ import ViewData from "./view-data";
export type DEFAULT_DOCUMENT_VIEW_TYPE = {
viewId: string;
- file: string | null;
- pages: { file: string; pageNumber: string; embeddedLinks: string[] }[] | null;
+ file?: string | null;
+ pages?:
+ | { file: string; pageNumber: string; embeddedLinks: string[] }[]
+ | null;
};
export default function DocumentView({
@@ -60,8 +62,6 @@ export default function DocumentView({
const [isLoading, setIsLoading] = useState<boolean>(false);
const [viewData, setViewData] = useState<DEFAULT_DOCUMENT_VIEW_TYPE>({
viewId: "",
- file: null,
- pages: null,
});
const [data, setData] = useState<DEFAULT_ACCESS_FORM_TYPE>(
DEFAULT_ACCESS_FORM_DATA,
diff --git a/pages/api/views.ts b/pages/api/views.ts
index fa9fb061..55f6c631 100644
--- a/pages/api/views.ts
+++ b/pages/api/views.ts
@@ -252,6 +252,7 @@ export default async function handle(
select: {
file: true,
storageType: true,
+ type: true,
},
});
@@ -260,10 +261,12 @@ export default async function handle(
return;
}
- documentVersion.file = await getFile({
- data: documentVersion.file,
- type: documentVersion.storageType,
- });
+ if (documentVersion.type === "pdf") {
+ documentVersion.file = await getFile({
+ data: documentVersion.file,
+ type: documentVersion.storageType,
+ });
+ }
console.timeEnd("get-file");
}
@@ -276,8 +279,11 @@ export default async function handle(
const returnObject = {
message: "View recorded",
viewId: newView.id,
- file: documentVersion ? documentVersion.file : null,
- pages: documentPages ? documentPages : null,
+ file:
+ documentVersion && documentVersion.type === "pdf"
+ ? documentVersion.file
+ : undefined,
+ pages: documentPages ? documentPages : undefined,
};
return res.status(200).json(returnObject);