From 1aff42f453b0f1095f24e0a210987e41f4b557d2 Mon Sep 17 00:00:00 2001 From: zadam Date: Fri, 17 Dec 2021 22:03:00 +0100 Subject: [PATCH] fix setting exported file extension when truncated --- src/services/export/zip.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/services/export/zip.js b/src/services/export/zip.js index 1af8efa7b..ffed0f5d9 100644 --- a/src/services/export/zip.js +++ b/src/services/export/zip.js @@ -50,7 +50,13 @@ function exportToZip(taskContext, branch, format, res) { } function getDataFileName(note, baseFileName, existingFileNames) { - const existingExtension = path.extname(baseFileName).toLowerCase(); + let fileName = baseFileName; + + if (fileName.length > 30) { + fileName = fileName.substr(0, 30); + } + + let existingExtension = path.extname(fileName).toLowerCase(); let newExtension; // following two are handled specifically since we always want to have these extensions no matter the automatic detection @@ -68,13 +74,12 @@ function exportToZip(taskContext, branch, format, res) { newExtension = null; } else { - newExtension = mimeTypes.extension(note.mime) || "dat"; - } - - let fileName = baseFileName; - - if (fileName.length > 30) { - fileName = fileName.substr(0, 30); + if (note.mime?.toLowerCase()?.trim() === "image/jpg") { + newExtension = 'jpg'; + } + else { + newExtension = mimeTypes.extension(note.mime) || "dat"; + } } // if the note is already named with extension (e.g. "jquery"), then it's silly to append exact same extension again