From 074eb1c02f7520ad85e70d88981b448092e6cc85 Mon Sep 17 00:00:00 2001 From: zadam Date: Wed, 15 Dec 2021 22:36:45 +0100 Subject: [PATCH 1/4] importing of cloned notes should not depend on ZIP listing order, fixes #2440 --- src/becca/entities/branch.js | 4 ++-- src/services/import/zip.js | 14 +++++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/becca/entities/branch.js b/src/becca/entities/branch.js index 6ac065c47..411d1812c 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/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; From a098630e09c5c31892317c747a82f075f37f5af5 Mon Sep 17 00:00:00 2001 From: zadam Date: Thu, 16 Dec 2021 22:10:51 +0100 Subject: [PATCH 2/4] add default JPG quality if value not in range --- src/public/app/dialogs/options/other.js | 4 ++-- src/services/image.js | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/public/app/dialogs/options/other.js b/src/public/app/dialogs/options/other.js index 30ef661b6..0be993a2d 100644 --- a/src/public/app/dialogs/options/other.js +++ b/src/public/app/dialogs/options/other.js @@ -34,8 +34,8 @@ const TPL = `
- - + +
diff --git a/src/services/image.js b/src/services/image.js index c6551f1e7..ce1ede3f4 100644 --- a/src/services/image.js +++ b/src/services/image.js @@ -122,7 +122,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 { From 1aff42f453b0f1095f24e0a210987e41f4b557d2 Mon Sep 17 00:00:00 2001 From: zadam Date: Fri, 17 Dec 2021 22:03:00 +0100 Subject: [PATCH 3/4] 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 From e29aee1aae4511372c6d1f0aab4267ec1a66883d Mon Sep 17 00:00:00 2001 From: zadam Date: Sun, 19 Dec 2021 10:36:48 +0100 Subject: [PATCH 4/4] use lazy title loading in bookmarks buttons to have decrypted title upon protected session start, #2393 --- src/public/app/widgets/buttons/button_widget.js | 5 ++++- src/public/app/widgets/buttons/open_note_button_widget.js | 7 ++++++- 2 files changed, 10 insertions(+), 2 deletions(-) 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(); });