Skip to content

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

fix: sign all pages for preview links to avoid 10-page limit

Cursor Agentcf32f42ababe
diff --git a/app/api/views-dataroom/route.ts b/app/api/views-dataroom/route.ts
index b1bc2187..c1ed64f6 100644
--- a/app/api/views-dataroom/route.ts
+++ b/app/api/views-dataroom/route.ts
@@ -893,10 +893,14 @@ export async function POST(request: NextRequest) {
// Sign URLs for pages around the requested start page (or page 1 by default).
// Remaining page URLs are fetched on-demand by the client via /api/views/pages.
+ // Preview mode signs all pages upfront since no viewId exists for on-demand loading.
+ const signAll = isPreview;
const centerIndex = Math.max(0, (startPage ?? 1) - 1);
const halfWindow = Math.floor(INITIAL_PAGES_TO_LOAD / 2);
- const signStart = Math.max(0, centerIndex - halfWindow);
- const signEnd = Math.min(documentPages.length, signStart + INITIAL_PAGES_TO_LOAD);
+ const signStart = signAll ? 0 : Math.max(0, centerIndex - halfWindow);
+ const signEnd = signAll
+ ? documentPages.length
+ : Math.min(documentPages.length, signStart + INITIAL_PAGES_TO_LOAD);
documentPages = await Promise.all(
documentPages.map(async (page, index) => {
diff --git a/app/api/views/route.ts b/app/api/views/route.ts
index 252187f1..51867810 100644
--- a/app/api/views/route.ts
+++ b/app/api/views/route.ts
@@ -612,16 +612,20 @@ export async function POST(request: NextRequest) {
// Sign URLs for pages around the requested start page (or page 1 by default).
// Remaining page URLs are fetched on-demand by the client via /api/views/pages.
+ // Preview mode signs all pages upfront since no viewId exists for on-demand loading.
+ const signAll = isPreview;
const centerIndex = Math.min(
Math.max(0, (startPage ?? 1) - 1),
Math.max(0, documentPages.length - 1),
);
const halfWindow = Math.floor(INITIAL_PAGES_TO_LOAD / 2);
- const signStart = Math.max(0, centerIndex - halfWindow);
- const signEnd = Math.min(
- documentPages.length,
- signStart + INITIAL_PAGES_TO_LOAD,
- );
+ const signStart = signAll ? 0 : Math.max(0, centerIndex - halfWindow);
+ const signEnd = signAll
+ ? documentPages.length
+ : Math.min(
+ documentPages.length,
+ signStart + INITIAL_PAGES_TO_LOAD,
+ );
documentPages = await Promise.all(
documentPages.map(async (page, index) => {