Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
feat: add new file type: msg
Marc Seitz2fb67b69aee5
diff --git a/components/document-upload.tsx b/components/document-upload.tsxindex 9f6905ce..cde5765e 100644--- a/components/document-upload.tsx+++ b/components/document-upload.tsx@@ -87,6 +87,7 @@ export default function DocumentUpload({"video/ogg": [], // ".ogg""application/vnd.google-earth.kml+xml": [".kml"], // ".kml""application/vnd.google-earth.kmz": [".kmz"], // ".kmz"+ "application/vnd.ms-outlook": [".msg"], // ".msg"},multiple: false,onDropAccepted: (acceptedFiles) => {diff --git a/components/upload-zone.tsx b/components/upload-zone.tsxindex 4f9edc47..53cee2f2 100644--- a/components/upload-zone.tsx+++ b/components/upload-zone.tsx@@ -1,11 +1,7 @@import { useRouter } from "next/router";--import { useCallback, useMemo, useRef, useState } from "react";--import { useTeam } from "@/context/team-context";import { DocumentStorageType } from "@prisma/client";import { useSession } from "next-auth/react";@@ -13,25 +9,26 @@ import { DropEvent, FileRejection, useDropzone } from "react-dropzone";import { toast } from "sonner";import { mutate } from "swr";--import { useAnalytics } from "@/lib/analytics";import { SUPPORTED_DOCUMENT_MIME_TYPES } from "@/lib/constants";import { DocumentData, createDocument } from "@/lib/documents/create-document";import { resumableUpload } from "@/lib/files/tus-upload";-import { createFolderInBoth, createFolderInMainDocs, isSystemFile } from "@/lib/folders/create-folder";+import {+ createFolderInBoth,+ createFolderInMainDocs,+ isSystemFile,+} from "@/lib/folders/create-folder";import { usePlan } from "@/lib/swr/use-billing";import useLimits from "@/lib/swr/use-limits";import { CustomUser } from "@/lib/types";import { cn } from "@/lib/utils";import { getSupportedContentType } from "@/lib/utils/get-content-type";-import { getFileSizeLimit, getFileSizeLimits } from "@/lib/utils/get-file-size-limits";+import {+ getFileSizeLimit,+ getFileSizeLimits,+} from "@/lib/utils/get-file-size-limits";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`@@ -73,6 +70,7 @@ const allAcceptableDropZoneMimeTypes = {"video/ogg": [], // ".ogg""application/vnd.google-earth.kml+xml": [".kml"], // ".kml""application/vnd.google-earth.kmz": [".kmz"], // ".kmz"+ "application/vnd.ms-outlook": [".msg"], // ".msg"};interface FileWithPaths extends File {@@ -601,18 +599,28 @@ export default function UploadZone({const browserFileTypeCompatibilityIssue = file.type === "";if (browserFileTypeCompatibilityIssue) {- const fileExtension = file.name.split(".").pop();- const correctFileType =- fileExtension &&- Object.keys(acceptableDropZoneFileTypes).find((fileType) =>- fileType.endsWith(fileExtension),- );+ const fileExtension = file.name.split(".").pop()?.toLowerCase();+ let correctMimeType: string | undefined;+ if (fileExtension) {+ // Iterate through acceptableDropZoneFileTypes to find the MIME type for the extension+ for (const [mime, extsUntyped] of Object.entries(+ acceptableDropZoneFileTypes,+ )) {+ const exts = extsUntyped as string[]; // Explicitly type exts+ if (+ exts.some((ext) => ext.toLowerCase() === "." + fileExtension)+ ) {+ correctMimeType = mime;+ break;+ }+ }+ }- if (correctFileType) {+ if (correctMimeType) {// if we can't do like ```file.type = fileType``` because of [Error: Setting getter-only property "type"]// The following is the only best way to resolve the problemfile = new File([file], file.name, {- type: correctFileType,+ type: correctMimeType,lastModified: file.lastModified,});}@@ -723,4 +731,4 @@ export default function UploadZone({{children}</div>);-}\ No newline at end of file+}diff --git a/components/viewer-upload-zone.tsx b/components/viewer-upload-zone.tsxindex 7409b933..80b0a2ff 100644--- a/components/viewer-upload-zone.tsx+++ b/components/viewer-upload-zone.tsx@@ -20,6 +20,7 @@ const acceptableViewerFileTypes = {"image/jpeg": [], // ".jpg""image/png": [], // ".png""image/jpg": [], // ".jpg"+ "application/vnd.ms-outlook": [".msg"], // ".msg"};export default function ViewerUploadZone({diff --git a/lib/api/documents/process-document.ts b/lib/api/documents/process-document.tsindex 7cb25dbb..cb586a99 100644--- a/lib/api/documents/process-document.ts+++ b/lib/api/documents/process-document.ts@@ -73,7 +73,7 @@ export const processDocument = async ({});// determine if the document is download only- const isDownloadOnly = type === "zip" || type === "map";+ const isDownloadOnly = type === "zip" || type === "map" || type === "email";// Save data to the databaseconst document = await prisma.document.create({diff --git a/lib/constants.ts b/lib/constants.tsindex ee72a436..c41005fb 100644--- a/lib/constants.ts+++ b/lib/constants.ts@@ -87,6 +87,7 @@ export const SUPPORTED_DOCUMENT_MIME_TYPES = ["video/ogg", // .ogg"application/vnd.google-earth.kml+xml", // .kml"application/vnd.google-earth.kmz", // .kmz+ "application/vnd.ms-outlook", // .msg];export const SUPPORTED_DOCUMENT_SIMPLE_TYPES = [@@ -100,6 +101,7 @@ export const SUPPORTED_DOCUMENT_SIMPLE_TYPES = ["zip","video","map",+ "email",] as const;export const VIDEO_EVENT_TYPES = [diff --git a/lib/utils/get-content-type.ts b/lib/utils/get-content-type.tsindex 22f2ea15..073b2400 100644--- a/lib/utils/get-content-type.ts+++ b/lib/utils/get-content-type.ts@@ -35,6 +35,8 @@ export function getSupportedContentType(contentType: string): string | null {case "application/vnd.google-earth.kml+xml":case "application/vnd.google-earth.kmz":return "map";+ case "application/vnd.ms-outlook":+ return "email";default:return null;}@@ -92,6 +94,8 @@ export function getExtensionFromContentType(return "kml";case "application/vnd.google-earth.kmz":return "kmz";+ case "application/vnd.ms-outlook":+ return "msg";default:return null;}diff --git a/lib/utils/get-file-icon.tsx b/lib/utils/get-file-icon.tsxindex ffe9a57c..d8023187 100644--- a/lib/utils/get-file-icon.tsx+++ b/lib/utils/get-file-icon.tsx@@ -1,4 +1,4 @@-import { FileIcon } from "lucide-react";+import { FileIcon, MailIcon } from "lucide-react";import CadIcon from "@/components/shared/icons/files/cad";import DocsIcon from "@/components/shared/icons/files/docs";@@ -61,6 +61,9 @@ export function fileIcon({case "application/vnd.google-earth.kmz":case "map":return <MapIcon className={className} isLight={isLight} />;+ case "application/vnd.ms-outlook":+ case "email":+ return <MailIcon className={className} />;default:return <FileIcon className={className} />;}