fix setting exported file extension when truncated

This commit is contained in:
zadam 2021-12-17 22:03:00 +01:00
parent a098630e09
commit 1aff42f453

View File

@ -50,7 +50,13 @@ function exportToZip(taskContext, branch, format, res) {
} }
function getDataFileName(note, baseFileName, existingFileNames) { 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; let newExtension;
// following two are handled specifically since we always want to have these extensions no matter the automatic detection // 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; newExtension = null;
} }
else { else {
newExtension = mimeTypes.extension(note.mime) || "dat"; if (note.mime?.toLowerCase()?.trim() === "image/jpg") {
} newExtension = 'jpg';
}
let fileName = baseFileName; else {
newExtension = mimeTypes.extension(note.mime) || "dat";
if (fileName.length > 30) { }
fileName = fileName.substr(0, 30);
} }
// if the note is already named with extension (e.g. "jquery"), then it's silly to append exact same extension again // if the note is already named with extension (e.g. "jquery"), then it's silly to append exact same extension again