diff --git a/src/lib/misc/ErrorHandler.tsx b/src/lib/misc/ErrorHandler.tsx index 96432231c..3a854fb62 100644 --- a/src/lib/misc/ErrorHandler.tsx +++ b/src/lib/misc/ErrorHandler.tsx @@ -14,6 +14,19 @@ export const NO_PACKAGE_ERROR = new Error( ) ); +const NOTION_INFO_LINK = + 'https://www.notion.so/help/export-your-content#export-as-html'; +export const UNSUPPORTED_FORMAT_MD = new Error( + renderToStaticMarkup( + <> + Markdown support has been removed, please Export as HTML:{' '} + + ${NOTION_INFO_LINK} + + + ) +); + export default function ErrorHandler(res: express.Response, err: Error) { if (process.env.NODE_ENV === 'production') { Sentry.captureException(err); diff --git a/src/routes/upload/helpers/TriggerUnsupportedFormat.ts b/src/routes/upload/helpers/TriggerUnsupportedFormat.ts deleted file mode 100644 index e204fd563..000000000 --- a/src/routes/upload/helpers/TriggerUnsupportedFormat.ts +++ /dev/null @@ -1,5 +0,0 @@ -export default function TriggerUnsupportedFormat() { - throw new Error( - 'Markdown support has been removed, please use HTML' - ); -} diff --git a/src/routes/upload/helpers/handleUpload.ts b/src/routes/upload/helpers/handleUpload.ts index 797266338..d346b75df 100644 --- a/src/routes/upload/helpers/handleUpload.ts +++ b/src/routes/upload/helpers/handleUpload.ts @@ -4,7 +4,10 @@ import StorageHandler from '../../../lib/storage/StorageHandler'; import { PrepareDeck } from '../../../lib/parser/DeckParser'; import Settings from '../../../lib/parser/Settings'; import { ZipHandler } from '../../../lib/anki/zip'; -import ErrorHandler, { NO_PACKAGE_ERROR } from '../../../lib/misc/ErrorHandler'; +import ErrorHandler, { + NO_PACKAGE_ERROR, + UNSUPPORTED_FORMAT_MD, +} from '../../../lib/misc/ErrorHandler'; import Package from '../../../lib/parser/Package'; import cleanDeckName from './cleanDeckname'; import { registerUploadSize } from './registerUploadSize'; @@ -19,7 +22,7 @@ export default async function handleUpload( try { const files = req.files as Express.Multer.File[]; let packages: Package[] = []; - + let hasMarkdown = false; for (const file of files) { const filename = file.originalname; const settings = new Settings(req.body || {}); @@ -38,7 +41,7 @@ export default async function handleUpload( packages = packages.concat(pkg); } } else if (filename.match(/.md$/)) { - TriggerUnsupportedFormat(); + hasMarkdown = true; } else { const zipHandler = new ZipHandler(); /* @ts-ignore */ @@ -49,6 +52,8 @@ export default async function handleUpload( if (d) { packages.push(new Package(d.name, d.apkg)); } + } else if (fileName.match(/.md$/)) { + hasMarkdown = true; } } } @@ -90,7 +95,11 @@ export default async function handleUpload( } else if (packages.length > 1) { sendBundle(packages, storage, res); } else { - ErrorHandler(res, NO_PACKAGE_ERROR); + if (hasMarkdown) { + ErrorHandler(res, UNSUPPORTED_FORMAT_MD); + } else { + ErrorHandler(res, NO_PACKAGE_ERROR); + } } } catch (err) { captureException(err);