From d4d48f3834825c8b0846d778702a9aed74a17739 Mon Sep 17 00:00:00 2001 From: zadam Date: Sat, 8 Jan 2022 21:50:16 +0100 Subject: [PATCH] use [protected] for protected notes in the export --- src/becca/becca_service.js | 9 +-------- src/becca/entities/note.js | 4 ++++ src/routes/api/note_map.js | 4 ++-- src/routes/api/tree.js | 2 +- src/services/export/zip.js | 9 +++++---- 5 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/becca/becca_service.js b/src/becca/becca_service.js index 92037178b..b27e985f5 100644 --- a/src/becca/becca_service.js +++ b/src/becca/becca_service.js @@ -71,14 +71,7 @@ function getNoteTitle(childNoteId, parentNoteId) { return "[error fetching title]"; } - let title; - - if (childNote.isProtected) { - title = protectedSessionService.isProtectedSessionAvailable() ? childNote.title : '[protected]'; - } - else { - title = childNote.title; - } + const title = childNote.getTitleOrProtected(); const branch = parentNote ? becca.getBranchFromChildAndParent(childNote.noteId, parentNote.noteId) : null; diff --git a/src/becca/entities/note.js b/src/becca/entities/note.js index bf4779bf0..2410d7a7f 100644 --- a/src/becca/entities/note.js +++ b/src/becca/entities/note.js @@ -131,6 +131,10 @@ class Note extends AbstractEntity { || protectedSessionService.isProtectedSessionAvailable() } + getTitleOrProtected() { + return this.isContentAvailable() ? this.title : '[protected]'; + } + /** @returns {Branch[]} */ getParentBranches() { return this.parentBranches; diff --git a/src/routes/api/note_map.js b/src/routes/api/note_map.js index 4455aebe7..4458797a9 100644 --- a/src/routes/api/note_map.js +++ b/src/routes/api/note_map.js @@ -98,7 +98,7 @@ function getLinkMap(req) { return [ note.noteId, - note.isContentAvailable() ? note.title : '[protected]', + note.getTitleOrProtected(), note.type ]; }); @@ -158,7 +158,7 @@ function getTreeMap(req) { .concat(...mapRootNote.getParentNotes()) .map(note => [ note.noteId, - note.isContentAvailable() ? note.title : '[protected]', + note.getTitleOrProtected(), note.type ]); diff --git a/src/routes/api/tree.js b/src/routes/api/tree.js index 0503c4202..3894fbce3 100644 --- a/src/routes/api/tree.js +++ b/src/routes/api/tree.js @@ -54,7 +54,7 @@ function getNotesAndBranchesAndAttributes(noteIds) { notes.push({ noteId: note.noteId, - title: note.isDecrypted ? note.title : '[protected]', + title: note.getTitleOrProtected(), isProtected: note.isProtected, type: note.type, mime: note.mime diff --git a/src/services/export/zip.js b/src/services/export/zip.js index ffed0f5d9..3e8e3ad4a 100644 --- a/src/services/export/zip.js +++ b/src/services/export/zip.js @@ -97,7 +97,8 @@ function exportToZip(taskContext, branch, format, res) { return; } - const completeTitle = branch.prefix ? (branch.prefix + ' - ' + note.title) : note.title; + const title = note.getTitleOrProtected(); + const completeTitle = branch.prefix ? (branch.prefix + ' - ' + title) : title; let baseFileName = sanitize(completeTitle); if (baseFileName.length > 200) { // actual limit is 256 bytes(!) but let's be conservative @@ -113,7 +114,7 @@ function exportToZip(taskContext, branch, format, res) { isClone: true, noteId: note.noteId, notePath: notePath, - title: note.title, + title: note.getTitleOrProtected(), prefix: branch.prefix, dataFileName: fileName, type: 'text', // export will have text description, @@ -125,7 +126,7 @@ function exportToZip(taskContext, branch, format, res) { isClone: false, noteId: note.noteId, notePath: notePath, - title: note.title, + title: note.getTitleOrProtected(), notePosition: branch.notePosition, prefix: branch.prefix, isExpanded: branch.isExpanded, @@ -445,7 +446,7 @@ ${content} } const note = branch.getNote(); - const zipFileName = (branch.prefix ? `${branch.prefix} - ` : "") + note.title + ".zip"; + const zipFileName = (branch.prefix ? `${branch.prefix} - ` : "") + note.getTitleOrProtected() + ".zip"; res.setHeader('Content-Disposition', utils.getContentDisposition(zipFileName)); res.setHeader('Content-Type', 'application/zip');