Skip to content

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

feat: update maximum file size for pro plan

Marc Seitzade4ddee5d13
diff --git a/components/document-upload.tsx b/components/document-upload.tsx
index c67faf2d..d628dde2 100644
--- a/components/document-upload.tsx
+++ b/components/document-upload.tsx
@@ -10,6 +10,8 @@ import {
Presentation as PresentationChartBarIcon,
Image as PhotoIcon,
} from "lucide-react";
+import { useTeam } from "@/context/team-context";
+import { usePlan } from "@/lib/swr/use-billing";
function fileIcon(fileType: string) {
switch (fileType) {
@@ -37,12 +39,14 @@ export default function DocumentUpload({
currentFile: File | null;
setCurrentFile: React.Dispatch<React.SetStateAction<File | null>>;
}) {
+ const { plan, loading } = usePlan();
+ const maxSize = plan?.plan === "pro" ? 100 : 30;
const { getRootProps, getInputProps } = useDropzone({
accept: {
"application/pdf": [], // ".pdf"
},
multiple: false,
- maxSize: 30 * 1024 * 1024, // 30 MB
+ maxSize: maxSize * 1024 * 1024, // 30 MB
onDropAccepted: (acceptedFiles) => {
setCurrentFile(acceptedFiles[0]);
},
@@ -50,7 +54,7 @@ export default function DocumentUpload({
const { errors } = fileRejections[0];
let message;
if (errors[0].code === "file-too-large") {
- message = "File size too big (max. 30 MB)";
+ message = `File size too big (max. ${maxSize} MB)`;
} else if (errors[0].code === "file-invalid-type") {
message = "File type not supported (.pdf only)";
} else {
@@ -103,7 +107,9 @@ export default function DocumentUpload({
</span>
</div>
<p className="text-xs leading-5 text-gray-500">
- {currentFile ? "Replace file?" : "Only *.pdf & 30 MB limit"}
+ {currentFile
+ ? "Replace file?"
+ : `Only *.pdf & ${maxSize} MB limit`}
</p>
</div>
</div>
diff --git a/pages/api/file/browser-upload.ts b/pages/api/file/browser-upload.ts
index 3a710139..845b0d01 100644
--- a/pages/api/file/browser-upload.ts
+++ b/pages/api/file/browser-upload.ts
@@ -23,9 +23,28 @@ export default async function handler(
throw new Error("Unauthorized");
}
+ const userId = (session.user as CustomUser).id;
+ const team = await prisma?.team.findFirst({
+ where: {
+ users: {
+ some: {
+ userId,
+ },
+ },
+ },
+ select: {
+ plan: true,
+ },
+ });
+
+ let maxSize = 30 * 1024 * 1024; // 30 MB
+ if (team?.plan === "pro") {
+ maxSize = 100 * 1024 * 1024; // 100 MB
+ }
+
return {
allowedContentTypes: ["application/pdf"],
- maximumSizeInBytes: 30 * 1024 * 1024, // 30 MB
+ maximumSizeInBytes: maxSize, // 30 MB
metadata: JSON.stringify({
// optional, sent to your server on upload completion
userId: (session.user as CustomUser).id,