Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
feat: add rtf / txt file support
Marc Seitz77cf84ef2cfe
diff --git a/components/document-upload.tsx b/components/document-upload.tsxindex d68aa951..8729ae29 100644--- a/components/document-upload.tsx+++ b/components/document-upload.tsx@@ -7,7 +7,11 @@ import { useTheme } from "next-themes";import { useDropzone } from "react-dropzone";import { toast } from "sonner";-import { SUPPORTED_DOCUMENT_MIME_TYPES } from "@/lib/constants";+import {+ FREE_PLAN_ACCEPTED_FILE_TYPES,+ FULL_PLAN_ACCEPTED_FILE_TYPES,+ SUPPORTED_DOCUMENT_MIME_TYPES,+} from "@/lib/constants";import { usePlan } from "@/lib/swr/use-billing";import useLimits from "@/lib/swr/use-limits";import { bytesToSize } from "@/lib/utils";@@ -46,49 +50,8 @@ export default function DocumentUpload({const { getRootProps, getInputProps } = useDropzone({accept:isFree && !isTrial- ? {- "application/pdf": [], // ".pdf"- "application/vnd.ms-excel": [], // ".xls"- "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":- [], // ".xlsx"- "text/csv": [], // ".csv"- "application/vnd.oasis.opendocument.spreadsheet": [], // ".ods"- "image/png": [], // ".png"- "image/jpeg": [], // ".jpeg"- "image/jpg": [], // ".jpg"- }- : {- "application/pdf": [], // ".pdf"- "application/vnd.ms-excel": [], // ".xls"- "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":- [], // ".xlsx"- "application/vnd.ms-excel.sheet.macroEnabled.12": [".xlsm"], // ".xlsm"- "text/csv": [], // ".csv"- "application/vnd.oasis.opendocument.spreadsheet": [], // ".ods"- "application/vnd.ms-powerpoint": [], // ".ppt"- "application/vnd.openxmlformats-officedocument.presentationml.presentation":- [], // ".pptx"- "application/vnd.oasis.opendocument.presentation": [], // ".odp"- "application/msword": [], // ".doc"- "application/vnd.openxmlformats-officedocument.wordprocessingml.document":- [], // ".docx"- "application/vnd.oasis.opendocument.text": [], // ".odt"- "image/vnd.dwg": [".dwg"], // ".dwg"- "image/vnd.dxf": [".dxf"], // ".dxf"- "image/png": [], // ".png"- "image/jpeg": [], // ".jpeg"- "image/jpg": [], // ".jpg"- "application/zip": [], // ".zip"- "application/x-zip-compressed": [], // ".zip"- "video/mp4": [], // ".mp4"- "video/quicktime": [], // ".mov"- "video/x-msvideo": [], // ".avi"- "video/webm": [], // ".webm"- "video/ogg": [], // ".ogg"- "application/vnd.google-earth.kml+xml": [".kml"], // ".kml"- "application/vnd.google-earth.kmz": [".kmz"], // ".kmz"- "application/vnd.ms-outlook": [".msg"], // ".msg"- },+ ? FREE_PLAN_ACCEPTED_FILE_TYPES+ : FULL_PLAN_ACCEPTED_FILE_TYPES,multiple: false,onDropAccepted: (acceptedFiles) => {if (acceptedFiles.length === 0) {@@ -229,7 +192,7 @@ export default function DocumentUpload({? "Replace file?": isFree && !isTrial? `Only *.pdf, *.xls, *.xlsx, *.csv, *.ods, *.png, *.jpeg, *.jpg`- : `Only *.pdf, *.pptx, *.docx, *.xlsx, *.xls, *.xlsm, *.csv, *.ods, *.ppt, *.odp, *.doc, *.odt, *.dwg, *.dxf, *.png, *.jpg, *.jpeg, *.mp4, *.mov, *.avi, *.webm, *.ogg`}+ : `Only *.pdf, *.pptx, *.docx, *.xlsx, *.xls, *.xlsm, *.csv, *.ods, *.ppt, *.odp, *.doc, *.odt, *.rtf, *txt, *.dwg, *.dxf, *.png, *.jpg, *.jpeg, *.mp4, *.mov, *.avi, *.webm, *.ogg`}</p></div></div>diff --git a/components/upload-zone.tsx b/components/upload-zone.tsxindex d4b38dc0..f3e6107f 100644--- a/components/upload-zone.tsx+++ b/components/upload-zone.tsx@@ -1,6 +1,6 @@import { useRouter } from "next/router";-import { useCallback, useMemo, useRef, useState } from "react";+import { useCallback, useMemo, useRef } from "react";import { useTeam } from "@/context/team-context";import { DocumentStorageType } from "@prisma/client";@@ -10,7 +10,11 @@ import { toast } from "sonner";import { mutate } from "swr";import { useAnalytics } from "@/lib/analytics";-import { SUPPORTED_DOCUMENT_MIME_TYPES } from "@/lib/constants";+import {+ FREE_PLAN_ACCEPTED_FILE_TYPES,+ FULL_PLAN_ACCEPTED_FILE_TYPES,+ SUPPORTED_DOCUMENT_MIME_TYPES,+} from "@/lib/constants";import { DocumentData, createDocument } from "@/lib/documents/create-document";import { resumableUpload } from "@/lib/files/tus-upload";import {@@ -33,46 +37,9 @@ import { getPagesCount } from "@/lib/utils/get-page-number-count";// Originally these mime values were directly used in the dropzone hook.// There was a solid reason to take them out of the scope, primarily to solve a browser compatibility issue to determine the file type when user dropped a folder.// you will figure out how this change helped to fix the compatibility issue once you have went through reading of `getFilesFromDropEvent` and `traverseFolder`-const acceptableDropZoneMimeTypesWhenIsFreePlanAndNotTrail = {- "application/pdf": [], // ".pdf"- "application/vnd.ms-excel": [], // ".xls"- "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": [], // ".xlsx"- "text/csv": [], // ".csv"- "application/vnd.oasis.opendocument.spreadsheet": [], // ".ods"- "image/png": [], // ".png"- "image/jpeg": [], // ".jpeg"- "image/jpg": [], // ".jpg"-};-const allAcceptableDropZoneMimeTypes = {- "application/pdf": [], // ".pdf"- "application/vnd.ms-excel": [], // ".xls"- "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": [], // ".xlsx"- "application/vnd.ms-excel.sheet.macroEnabled.12": [".xlsm"], // ".xlsm"- "text/csv": [], // ".csv"- "application/vnd.oasis.opendocument.spreadsheet": [], // ".ods"- "application/vnd.openxmlformats-officedocument.wordprocessingml.document": [], // ".docx"- "application/vnd.openxmlformats-officedocument.presentationml.presentation":- [], // ".pptx"- "application/vnd.ms-powerpoint": [], // ".ppt"- "application/msword": [], // ".doc"- "application/vnd.oasis.opendocument.text": [], // ".odt"- "application/vnd.oasis.opendocument.presentation": [], // ".odp"- "image/vnd.dwg": [".dwg"], // ".dwg"- "image/vnd.dxf": [".dxf"], // ".dxf"- "image/png": [], // ".png"- "image/jpeg": [], // ".jpeg"- "image/jpg": [], // ".jpg"- "application/zip": [], // ".zip"- "application/x-zip-compressed": [], // ".zip"- "video/mp4": [], // ".mp4"- "video/webm": [], // ".webm"- "video/quicktime": [], // ".mov"- "video/x-msvideo": [], // ".avi"- "video/ogg": [], // ".ogg"- "application/vnd.google-earth.kml+xml": [".kml"], // ".kml"- "application/vnd.google-earth.kmz": [".kmz"], // ".kmz"- "application/vnd.ms-outlook": [".msg"], // ".msg"-};+const acceptableDropZoneMimeTypesWhenIsFreePlanAndNotTrial =+ FREE_PLAN_ACCEPTED_FILE_TYPES;+const allAcceptableDropZoneMimeTypes = FULL_PLAN_ACCEPTED_FILE_TYPES;interface FileWithPaths extends File {path?: string;@@ -134,8 +101,6 @@ export default function UploadZone({? limits?.documents - limits?.usage?.documents: 0;- const [progress, setProgress] = useState<number>(0);- const [showProgress, setShowProgress] = useState(false);const uploadProgress = useRef<number[]>([]);const fileSizeLimits = useMemo(@@ -150,7 +115,7 @@ export default function UploadZone({const acceptableDropZoneFileTypes =isFree && !isTrial- ? acceptableDropZoneMimeTypesWhenIsFreePlanAndNotTrail+ ? acceptableDropZoneMimeTypesWhenIsFreePlanAndNotTrial: allAcceptableDropZoneMimeTypes;// this var will help to determine the correct api endpoint to request folder creation (If needed).diff --git a/components/viewer-upload-zone.tsx b/components/viewer-upload-zone.tsxindex 7409b933..16a3d958 100644--- a/components/viewer-upload-zone.tsx+++ b/components/viewer-upload-zone.tsx@@ -4,6 +4,7 @@ import { DocumentStorageType } from "@prisma/client";import { FileRejection, useDropzone } from "react-dropzone";import { toast } from "sonner";+import { VIEWER_ACCEPTED_FILE_TYPES } from "@/lib/constants";import { DocumentData } from "@/lib/documents/create-document";import { viewerUpload } from "@/lib/files/viewer-tus-upload";import { cn } from "@/lib/utils";@@ -11,16 +12,7 @@ import { getSupportedContentType } from "@/lib/utils/get-content-type";import { getPagesCount } from "@/lib/utils/get-page-number-count";// File types allowed for viewer uploads-const acceptableViewerFileTypes = {- "application/pdf": [], // ".pdf"- "application/vnd.ms-excel": [], // ".xls"- "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": [], // ".xlsx"- "text/csv": [], // ".csv"- "application/vnd.oasis.opendocument.spreadsheet": [], // ".ods"- "image/jpeg": [], // ".jpg"- "image/png": [], // ".png"- "image/jpg": [], // ".jpg"-};+const acceptableViewerFileTypes = VIEWER_ACCEPTED_FILE_TYPES;export default function ViewerUploadZone({children,diff --git a/lib/constants.ts b/lib/constants.tsindex c78a1b03..2a7fca97 100644--- a/lib/constants.ts+++ b/lib/constants.ts@@ -77,6 +77,9 @@ export const SUPPORTED_DOCUMENT_MIME_TYPES = ["application/msword", // .doc"application/vnd.openxmlformats-officedocument.wordprocessingml.document", // .docx"application/vnd.oasis.opendocument.text", // .odt+ "application/rtf", // .rtf+ "text/rtf", // .rtf+ "text/plain", // .txt"image/vnd.dwg", // .dwg"image/vnd.dxf", // .dxf"image/png", // .png@@ -94,6 +97,63 @@ export const SUPPORTED_DOCUMENT_MIME_TYPES = ["application/vnd.ms-outlook", // .msg];+// Upload configurations for different plan types and contexts+export const FREE_PLAN_ACCEPTED_FILE_TYPES = {+ "application/pdf": [], // ".pdf"+ "application/vnd.ms-excel": [], // ".xls"+ "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": [], // ".xlsx"+ "text/csv": [], // ".csv"+ "application/vnd.oasis.opendocument.spreadsheet": [], // ".ods"+ "image/png": [], // ".png"+ "image/jpeg": [], // ".jpeg"+ "image/jpg": [], // ".jpg"+};++export const FULL_PLAN_ACCEPTED_FILE_TYPES = {+ "application/pdf": [], // ".pdf"+ "application/vnd.ms-excel": [], // ".xls"+ "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": [], // ".xlsx"+ "application/vnd.ms-excel.sheet.macroEnabled.12": [".xlsm"], // ".xlsm"+ "text/csv": [], // ".csv"+ "application/vnd.oasis.opendocument.spreadsheet": [], // ".ods"+ "application/vnd.ms-powerpoint": [], // ".ppt"+ "application/vnd.openxmlformats-officedocument.presentationml.presentation":+ [], // ".pptx"+ "application/vnd.oasis.opendocument.presentation": [], // ".odp"+ "application/msword": [], // ".doc"+ "application/vnd.openxmlformats-officedocument.wordprocessingml.document": [], // ".docx"+ "application/vnd.oasis.opendocument.text": [], // ".odt"+ "application/rtf": [], // ".rtf"+ "text/rtf": [], // ".rtf"+ "text/plain": [], // ".txt"+ "image/vnd.dwg": [".dwg"], // ".dwg"+ "image/vnd.dxf": [".dxf"], // ".dxf"+ "image/png": [], // ".png"+ "image/jpeg": [], // ".jpeg"+ "image/jpg": [], // ".jpg"+ "application/zip": [], // ".zip"+ "application/x-zip-compressed": [], // ".zip"+ "video/mp4": [], // ".mp4"+ "video/quicktime": [], // ".mov"+ "video/x-msvideo": [], // ".avi"+ "video/webm": [], // ".webm"+ "video/ogg": [], // ".ogg"+ "application/vnd.google-earth.kml+xml": [".kml"], // ".kml"+ "application/vnd.google-earth.kmz": [".kmz"], // ".kmz"+ "application/vnd.ms-outlook": [".msg"], // ".msg"+};++export const VIEWER_ACCEPTED_FILE_TYPES = {+ "application/pdf": [], // ".pdf"+ "application/vnd.ms-excel": [], // ".xls"+ "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": [], // ".xlsx"+ "text/csv": [], // ".csv"+ "application/vnd.oasis.opendocument.spreadsheet": [], // ".ods"+ "image/jpeg": [], // ".jpg"+ "image/png": [], // ".png"+ "image/jpg": [], // ".jpg"+};+export const SUPPORTED_DOCUMENT_SIMPLE_TYPES = ["pdf","notion",diff --git a/lib/utils/get-content-type.ts b/lib/utils/get-content-type.tsindex 3d00149a..0c1a354a 100644--- a/lib/utils/get-content-type.ts+++ b/lib/utils/get-content-type.ts@@ -11,6 +11,9 @@ export function getSupportedContentType(contentType: string): string | null {case "application/msword":case "application/vnd.openxmlformats-officedocument.wordprocessingml.document":case "application/vnd.oasis.opendocument.text":+ case "application/rtf":+ case "text/rtf":+ case "text/plain":return "docs";case "application/vnd.ms-powerpoint":case "application/vnd.openxmlformats-officedocument.presentationml.presentation":@@ -70,6 +73,11 @@ export function getExtensionFromContentType(return "ppt";case "application/msword":return "doc";+ case "application/rtf":+ case "text/rtf":+ return "rtf";+ case "text/plain":+ return "txt";case "image/vnd.dwg":return "dwg";case "image/vnd.dxf":@@ -101,12 +109,15 @@ export function getExtensionFromContentType(}}-export function supportsAdvancedExcelMode(contentType: string | null | undefined): boolean {+export function supportsAdvancedExcelMode(+ contentType: string | null | undefined,+): boolean {if (!contentType) return false;return (contentType === "application/vnd.ms-excel" || // .xls- contentType === "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" || // .xlsx+ contentType ===+ "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" || // .xlsxcontentType === "application/vnd.ms-excel.sheet.macroEnabled.12" // .xlsm);}