fix: Unknown mimetype should fallback to Markdown parsing if markdown extension (#1678)

closes #1675
This commit is contained in:
Tom Moor
2020-11-26 21:16:56 -08:00
committed by GitHub
parent ac349b40f5
commit 6eda1cc0d3
2 changed files with 31 additions and 2 deletions

View File

@ -1,5 +1,6 @@
// @flow
import fs from "fs";
import path from "path";
import File from "formidable/lib/file";
import { strikethrough, tables } from "joplin-turndown-plugin-gfm";
import mammoth from "mammoth";
@ -139,7 +140,16 @@ export default async function documentImporter({
file: File,
ip: string,
}): Promise<{ text: string, title: string }> {
const fileInfo = importMapping.filter((item) => item.type === file.type)[0];
const fileInfo = importMapping.filter((item) => {
if (item.type === file.type) {
return true;
}
if (item.type === "text/markdown" && path.extname(file.name) === ".md") {
return true;
}
return false;
})[0];
if (!fileInfo) {
throw new InvalidRequestError(`File type ${file.type} not supported`);
}