From fa5d982a553ec428d521716c009da9382634c04f Mon Sep 17 00:00:00 2001 From: zadam Date: Sun, 17 May 2020 21:07:54 +0200 Subject: [PATCH] fix exporting root note, closes #1024 --- src/public/app/services/tree.js | 9 ++++++++- src/routes/api/export.js | 10 +++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/public/app/services/tree.js b/src/public/app/services/tree.js index 4910f4c36..40254a890 100644 --- a/src/public/app/services/tree.js +++ b/src/public/app/services/tree.js @@ -162,6 +162,13 @@ function getNoteIdFromNotePath(notePath) { } function getNoteIdAndParentIdFromNotePath(notePath) { + if (notePath === 'root') { + return { + noteId: 'root', + parentNoteId: 'none' + }; + } + let parentNoteId = 'root'; let noteId = ''; @@ -286,4 +293,4 @@ export default { getNotePathTitle, getHashValueFromAddress, parseNotePath -}; \ No newline at end of file +}; diff --git a/src/routes/api/export.js b/src/routes/api/export.js index 7464c793a..109b9bb7b 100644 --- a/src/routes/api/export.js +++ b/src/routes/api/export.js @@ -11,6 +11,14 @@ async function exportBranch(req, res) { const {branchId, type, format, version, taskId} = req.params; const branch = await repository.getBranch(branchId); + if (!branch) { + const message = `Cannot export branch ${branchId} since it does not exist.`; + log.error(message); + + res.status(500).send(message); + return; + } + const taskContext = new TaskContext(taskId, 'export'); try { @@ -39,4 +47,4 @@ async function exportBranch(req, res) { module.exports = { exportBranch -}; \ No newline at end of file +};