diff --git a/src/becca/entities/branch.js b/src/becca/entities/branch.js index c7d24c597..013a0f98e 100644 --- a/src/becca/entities/branch.js +++ b/src/becca/entities/branch.js @@ -84,7 +84,7 @@ class Branch extends AbstractEntity { /** @returns {Note} */ get childNote() { if (!(this.noteId in this.becca.notes)) { - // entities can come out of order in sync, create skeleton which will be filled later + // entities can come out of order in sync/import, create skeleton which will be filled later this.becca.addNote(this.noteId, new Note({noteId: this.noteId})); } @@ -98,7 +98,7 @@ class Branch extends AbstractEntity { /** @returns {Note} */ get parentNote() { if (!(this.parentNoteId in this.becca.notes)) { - // entities can come out of order in sync, create skeleton which will be filled later + // entities can come out of order in sync/import, create skeleton which will be filled later this.becca.addNote(this.parentNoteId, new Note({noteId: this.parentNoteId})); } diff --git a/src/public/app/dialogs/options/other.js b/src/public/app/dialogs/options/other.js index c2ec0eca2..ff97a0bcd 100644 --- a/src/public/app/dialogs/options/other.js +++ b/src/public/app/dialogs/options/other.js @@ -47,8 +47,8 @@ const TPL = `
- - + +
diff --git a/src/public/app/widgets/buttons/button_widget.js b/src/public/app/widgets/buttons/button_widget.js index 0740aeca8..d925f2357 100644 --- a/src/public/app/widgets/buttons/button_widget.js +++ b/src/public/app/widgets/buttons/button_widget.js @@ -44,7 +44,10 @@ export default class ButtonWidget extends NoteContextAwareWidget { this.$widget.tooltip({ html: true, title: () => { - const title = this.settings.title; + const title = typeof this.settings.title === "function" + ? this.settings.title() + : this.settings.title; + const action = actions.find(act => act.actionName === this.settings.command); if (action && action.effectiveShortcuts.length > 0) { diff --git a/src/public/app/widgets/buttons/open_note_button_widget.js b/src/public/app/widgets/buttons/open_note_button_widget.js index 8e68e4ebd..d1a206307 100644 --- a/src/public/app/widgets/buttons/open_note_button_widget.js +++ b/src/public/app/widgets/buttons/open_note_button_widget.js @@ -18,7 +18,12 @@ export default class OpenNoteButtonWidget extends ButtonWidget { } this.icon(note.getIcon()); - this.title(note.title); + this.title(() => { + const n = froca.getNoteFromCache(noteId); + + // always fresh, always decoded (when protected session is available) + return n.title; + }); this.refreshIcon(); }); 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 diff --git a/src/services/image.js b/src/services/image.js index 74e74224c..9457d1aa4 100644 --- a/src/services/image.js +++ b/src/services/image.js @@ -123,7 +123,11 @@ function saveImage(parentNoteId, uploadBuffer, originalName, shrinkImageSwitch, } async function shrinkImage(buffer, originalName) { - const jpegQuality = optionService.getOptionInt('imageJpegQuality'); + let jpegQuality = optionService.getOptionInt('imageJpegQuality'); + + if (jpegQuality < 10 || jpegQuality > 100) { + jpegQuality = 75; + } let finalImageBuffer; try { diff --git a/src/services/import/zip.js b/src/services/import/zip.js index 9645e9c10..7d68c2776 100644 --- a/src/services/import/zip.js +++ b/src/services/import/zip.js @@ -351,7 +351,19 @@ async function importZip(taskContext, fileBuffer, importRootNote) { let note = becca.getNote(noteId); + const isProtected = importRootNote.isProtected && protectedSessionService.isProtectedSessionAvailable(); + if (note) { + // only skeleton was created because of altered order of cloned notes in ZIP, we need to update + // https://github.com/zadam/trilium/issues/2440 + if (note.type === undefined) { + note.type = type; + note.mime = mime; + note.title = noteTitle; + note.isProtected = isProtected; + note.save(); + } + note.setContent(content); } else { @@ -367,7 +379,7 @@ async function importZip(taskContext, fileBuffer, importRootNote) { // root notePosition should be ignored since it relates to original document // now import root should be placed after existing notes into new parent notePosition: (noteMeta && firstNote) ? noteMeta.notePosition : undefined, - isProtected: importRootNote.isProtected && protectedSessionService.isProtectedSessionAvailable(), + isProtected: isProtected, })); createdNoteIds[note.noteId] = true;