Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
fix: don't let startPage exceed the document page length
Marc Seitz50b960dd909c
diff --git a/app/api/views/route.ts b/app/api/views/route.tsindex a157bce3..252187f1 100644--- a/app/api/views/route.ts+++ b/app/api/views/route.ts@@ -612,10 +612,16 @@ 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.- const centerIndex = Math.max(0, (startPage ?? 1) - 1);+ 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 signEnd = Math.min(+ documentPages.length,+ signStart + INITIAL_PAGES_TO_LOAD,+ );documentPages = await Promise.all(documentPages.map(async (page, index) => {