Skip to content

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

feat: update record_view api with versionNumber

Marc Seitz750e46be865f
diff --git a/components/PDFViewer.tsx b/components/PDFViewer.tsx
index 9e10f6dc..9b57bab1 100644
--- a/components/PDFViewer.tsx
+++ b/components/PDFViewer.tsx
@@ -46,6 +46,7 @@ export default function PDFViewer(props: any) {
}
// Send the last page view when the user leaves the page
+ // duration is measured in milliseconds
useEffect(() => {
const handleBeforeUnload = () => {
const endTime = Date.now();
@@ -95,6 +96,7 @@ export default function PDFViewer(props: any) {
viewId: props.viewId,
duration: duration,
pageNumber: pageNumberRef.current,
+ versionNumber: props.versionNumber,
}),
headers: {
"Content-Type": "application/json",
diff --git a/components/view/document-view.tsx b/components/view/document-view.tsx
index b9b9d455..65f2d7d7 100644
--- a/components/view/document-view.tsx
+++ b/components/view/document-view.tsx
@@ -168,6 +168,7 @@ export default function DocumentView({
viewId={viewData.viewId}
linkId={link.id}
documentId={document.id}
+ versionNumber={document.versions[0].versionNumber}
/>
</div>
);
diff --git a/lib/types.ts b/lib/types.ts
index 6edd4476..90c2371e 100644
--- a/lib/types.ts
+++ b/lib/types.ts
@@ -31,7 +31,9 @@ export interface LinkWithViews extends Link {
}
export interface LinkWithDocument extends Link {
- document: Document;
+ document: Document & {
+ versions: { versionNumber: number }[];
+ };
}
export interface Geo {
diff --git a/pages/api/links/[id]/index.ts b/pages/api/links/[id]/index.ts
index 85725de2..f1c09bb0 100644
--- a/pages/api/links/[id]/index.ts
+++ b/pages/api/links/[id]/index.ts
@@ -23,10 +23,21 @@ export default async function handle(
expiresAt: true,
emailProtected: true,
password: true,
- document: { select: { id: true } },
+ document: {
+ select: {
+ id: true,
+ versions: {
+ where: { isPrimary: true },
+ select: { versionNumber: true },
+ take: 1,
+ }
+ }
+ },
},
});
+ console.log("link", link);
+
return res.status(200).json(link);
} catch (error) {
return res.status(500).json({
diff --git a/pages/api/links/domains/[domain]/[slug]/index.ts b/pages/api/links/domains/[domain]/[slug]/index.ts
index 8b1b8cc1..2e6a4441 100644
--- a/pages/api/links/domains/[domain]/[slug]/index.ts
+++ b/pages/api/links/domains/[domain]/[slug]/index.ts
@@ -22,7 +22,16 @@ export default async function handle(
expiresAt: true,
emailProtected: true,
password: true,
- document: { select: { id: true } },
+ document: {
+ select: {
+ id: true,
+ versions: {
+ where: { isPrimary: true },
+ select: { versionNumber: true },
+ take: 1,
+ },
+ },
+ },
},
});
diff --git a/pages/api/record_view.ts b/pages/api/record_view.ts
index 823ae11e..d363cc71 100644
--- a/pages/api/record_view.ts
+++ b/pages/api/record_view.ts
@@ -14,6 +14,7 @@ const bodyValidation = z.object({
linkId: z.string(),
documentId: z.string(),
viewId: z.string(),
+ versionNumber: z.number().int().optional(),
time: z.number().int(),
duration: z.number().int(),
pageNumber: z.string(),
@@ -55,18 +56,18 @@ export default async function handle(
const referer = req.headers.referer;
const ua = userAgentFromString(req.headers["user-agent"]);
- const { linkId, documentId, viewId, duration, pageNumber } = req.body;
+ const { linkId, documentId, viewId, duration, pageNumber, versionNumber } = req.body;
const time = Date.now(); // in milliseconds
const pageViewId = newId("view");
-
const pageViewObject = {
id: pageViewId,
linkId,
documentId,
viewId,
+ versionNumber: versionNumber || 1,
time,
duration,
pageNumber: pageNumber.toString(),