Skip to content

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

feat: add maxPages as an configable option

Marc Seitz4fec2a6d1c2c
diff --git a/components/document-upload.tsx b/components/document-upload.tsx
index 7a350a2f..31bcfadc 100644
--- a/components/document-upload.tsx
+++ b/components/document-upload.tsx
@@ -34,7 +34,7 @@ export default function DocumentUpload({
const isFreePlan = plan === "free";
const isTrial = !!trial;
// const maxSize = isFreePlan && !isTrial ? 30 : 100;
- const maxNumPages = isFreePlan && !isTrial ? 100 : 500;
+ // const maxNumPages = isFreePlan && !isTrial ? 100 : 500;
// Get file size limits
const fileSizeLimits = useMemo(
@@ -124,8 +124,10 @@ export default function DocumentUpload({
.arrayBuffer()
.then((buffer) => {
getPagesCount(buffer).then((numPages) => {
- if (numPages > maxNumPages) {
- toast.error(`File has too many pages (max. ${maxNumPages})`);
+ if (numPages > fileSizeLimits.maxPages) {
+ toast.error(
+ `File has too many pages (max. ${fileSizeLimits.maxPages})`,
+ );
} else {
setCurrentFile(file);
}
diff --git a/components/upload-zone.tsx b/components/upload-zone.tsx
index edcb40b6..74d47c58 100644
--- a/components/upload-zone.tsx
+++ b/components/upload-zone.tsx
@@ -111,7 +111,7 @@ export default function UploadZone({
const isFreePlan = plan === "free";
const isTrial = !!trial;
// const maxSize = isFreePlan && !isTrial ? 30 : 350;
- const maxNumPages = isFreePlan && !isTrial ? 100 : 500;
+ // const maxNumPages = isFreePlan && !isTrial ? 100 : 500;
const { limits, canAddDocuments } = useLimits();
const remainingDocuments = limits?.documents
? limits?.documents - limits?.usage?.documents
@@ -226,7 +226,7 @@ export default function UploadZone({
const buffer = await file.arrayBuffer();
numPages = await getPagesCount(buffer);
- if (numPages > maxNumPages) {
+ if (numPages > fileSizeLimits.maxPages) {
setUploads((prev) =>
prev.filter((upload) => upload.fileName !== file.name),
);
@@ -234,7 +234,7 @@ export default function UploadZone({
return setRejectedFiles((prev) => [
{
fileName: file.name,
- message: `File has too many pages (max. ${maxNumPages})`,
+ message: `File has too many pages (max. ${fileSizeLimits.maxPages})`,
},
...prev,
]);
diff --git a/ee/limits/server.ts b/ee/limits/server.ts
index 2fefa056..bb8ac223 100644
--- a/ee/limits/server.ts
+++ b/ee/limits/server.ts
@@ -25,7 +25,7 @@ const planLimitsMap: Record<string, TPlanLimits> = {
"datarooms-plus": DATAROOMS_PLUS_PLAN_LIMITS,
};
-const configSchema = z.object({
+export const configSchema = z.object({
datarooms: z.number(),
links: z
.preprocess((v) => (v === null ? Infinity : Number(v)), z.number())
@@ -41,6 +41,7 @@ const configSchema = z.object({
customDomainInDataroom: z.boolean(),
advancedLinkControlsOnPro: z.boolean().nullish(),
watermarkOnBusiness: z.boolean().nullish(),
+ conversationsInDataroom: z.boolean().nullish(),
fileSizeLimits: z
.object({
video: z.number().optional(), // in MB
@@ -48,6 +49,7 @@ const configSchema = z.object({
image: z.number().optional(), // in MB
excel: z.number().optional(), // in MB
maxFiles: z.number().optional(), // in amount of files
+ maxPages: z.number().optional(), // in amount of pages
})
.optional(),
});
diff --git a/ee/limits/swr-handler.ts b/ee/limits/swr-handler.ts
index 30ef4977..0b02514e 100644
--- a/ee/limits/swr-handler.ts
+++ b/ee/limits/swr-handler.ts
@@ -1,32 +1,17 @@
import { useTeam } from "@/context/team-context";
import useSWR from "swr";
+import { z } from "zod";
import { fetcher } from "@/lib/utils";
-export type LimitProps = {
- datarooms: number;
- links: number | undefined | null;
- documents: number | undefined | null;
- users: number;
- domains: number;
- customDomainOnPro: boolean;
- customDomainInDataroom: boolean;
- advancedLinkControlsOnPro: boolean | undefined | null;
- watermarkOnBusiness: boolean | undefined | null;
+import { configSchema } from "./server";
+
+export type LimitProps = z.infer<typeof configSchema> & {
usage: {
documents: number;
links: number;
users: number;
};
- fileSizeLimits:
- | {
- video: number | undefined;
- document: number | undefined;
- image: number | undefined;
- excel: number | undefined;
- maxFiles: number | undefined;
- }
- | undefined;
};
export function useLimits() {
diff --git a/lib/utils/get-file-size-limits.ts b/lib/utils/get-file-size-limits.ts
index 9254e187..375de672 100644
--- a/lib/utils/get-file-size-limits.ts
+++ b/lib/utils/get-file-size-limits.ts
@@ -4,6 +4,7 @@ type FileSizeLimits = {
image: number;
excel: number;
maxFiles: number;
+ maxPages: number;
};
export function getFileSizeLimits({
@@ -22,6 +23,7 @@ export function getFileSizeLimits({
image: isFreePlan && !isTrial ? 30 : 100, // 30MB free, 100MB paid
excel: 40, // 40MB
maxFiles: 150,
+ maxPages: isFreePlan && !isTrial ? 100 : 500,
};
// If no custom limits are set, return default limits
@@ -36,6 +38,7 @@ export function getFileSizeLimits({
image: limits.fileSizeLimits.image ?? defaultLimits.image,
excel: limits.fileSizeLimits.excel ?? defaultLimits.excel,
maxFiles: limits.fileSizeLimits.maxFiles ?? defaultLimits.maxFiles,
+ maxPages: limits.fileSizeLimits.maxPages ?? defaultLimits.maxPages,
};
}