Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
Add timeout to document download fetch request.
Cursor Agent45c2599c3e16
diff --git a/pages/api/teams/[teamId]/agreements/[agreementId]/download.ts b/pages/api/teams/[teamId]/agreements/[agreementId]/download.tsindex 83f1e9e7..677f24e4 100644--- a/pages/api/teams/[teamId]/agreements/[agreementId]/download.ts+++ b/pages/api/teams/[teamId]/agreements/[agreementId]/download.ts@@ -1,6 +1,5 @@import { NextApiRequest, NextApiResponse } from "next";-import { DocumentStorageType } from "@prisma/client";import { authOptions } from "@/pages/api/auth/[...nextauth]";import { getServerSession } from "next-auth/next";@@ -135,8 +134,17 @@ export default async function handle(isDownload: true,});- // Fetch the actual file content- const fileResponse = await fetch(fileUrl);+// Fetch the actual file content with safety measures+ const controller = new AbortController();+ const timeoutId = setTimeout(() => controller.abort(), 30000); // 30 second timeout++ const fileResponse = await fetch(fileUrl, {+ signal: controller.signal,+ // Add size limit check in the response handling+ });++ clearTimeout(timeoutId);+if (!fileResponse.ok) {throw new Error("Failed to fetch document content");