Skip to content

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

feat: treat markdown uploads as download-only and skip conversion

Marc Seitz5da9edf74078
diff --git a/lib/api/documents/process-document.ts b/lib/api/documents/process-document.ts
index 592acf3e..3bb974b5 100644
--- a/lib/api/documents/process-document.ts
+++ b/lib/api/documents/process-document.ts
@@ -9,6 +9,7 @@ import {
import { processVideo } from "@/lib/trigger/optimize-video-files";
import { convertPdfToImageRoute } from "@/lib/trigger/pdf-to-image-route";
import { getExtension } from "@/lib/utils";
+import { isMarkdownFile } from "@/lib/utils/get-content-type";
import { conversionQueueName } from "@/lib/utils/trigger-utils";
import { sendDocumentCreatedWebhook } from "@/lib/webhook/triggers/document-created";
import { sendLinkCreatedWebhook } from "@/lib/webhook/triggers/link-created";
@@ -74,6 +75,8 @@ export const processDocument = async ({
name,
);
+ const isMarkdown = isMarkdownFile({ name, contentType });
+
// determine if the document is download only
const isDownloadOnly =
type === "zip" ||
@@ -82,6 +85,7 @@ export const processDocument = async ({
type === "other" ||
contentType === "text/tab-separated-values" ||
type === "cad" ||
+ isMarkdown ||
isDownloadOnlyByExtension;
// Save data to the database
@@ -154,7 +158,8 @@ export const processDocument = async ({
);
} else if (
(type === "docs" || type === "slides") &&
- !isDownloadOnlyByExtension
+ !isDownloadOnlyByExtension &&
+ !isMarkdown
) {
await convertFilesToPdfTask.trigger(
{
diff --git a/lib/utils/get-content-type.ts b/lib/utils/get-content-type.ts
index 6ff7edcd..dbda154c 100644
--- a/lib/utils/get-content-type.ts
+++ b/lib/utils/get-content-type.ts
@@ -72,6 +72,19 @@ export function getSupportedContentType(contentType: string): string | null {
}
}
+// Checks the extension too because browsers often upload `.md` as `text/plain`.
+export function isMarkdownFile({
+ name,
+ contentType,
+}: {
+ name?: string | null;
+ contentType?: string | null;
+}): boolean {
+ if (contentType === "text/markdown") return true;
+ if (name && /\.(md|markdown|mdown|mkd|mdx)$/i.test(name)) return true;
+ return false;
+}
+
export function getExtensionFromContentType(
contentType: string,
): string | null {
diff --git a/pages/api/teams/[teamId]/documents/[id]/versions/index.ts b/pages/api/teams/[teamId]/documents/[id]/versions/index.ts
index ff5d7c85..b06d5bc0 100644
--- a/pages/api/teams/[teamId]/documents/[id]/versions/index.ts
+++ b/pages/api/teams/[teamId]/documents/[id]/versions/index.ts
@@ -13,6 +13,7 @@ import { processVideo } from "@/lib/trigger/optimize-video-files";
import { convertPdfToImageRoute } from "@/lib/trigger/pdf-to-image-route";
import { CustomUser } from "@/lib/types";
import { log } from "@/lib/utils";
+import { isMarkdownFile } from "@/lib/utils/get-content-type";
import { conversionQueueName } from "@/lib/utils/trigger-utils";
import { documentUploadSchema } from "@/lib/zod/url-validation";
@@ -165,9 +166,12 @@ export default async function handle(
const isDownloadOnlyByExtension =
/\.(log|err|prj|jgw|tif|tiff|ecw|bak)$/i.test(url);
+ const isMarkdown = isMarkdownFile({ name: url, contentType });
+
if (
(type === "docs" || type === "slides") &&
- !isDownloadOnlyByExtension
+ !isDownloadOnlyByExtension &&
+ !isMarkdown
) {
await convertFilesToPdfTask.trigger(
{