From ea6e56842fe9d1ae4be67ab5a91167ba17805938 Mon Sep 17 00:00:00 2001 From: anasasilva Date: Thu, 13 Dec 2018 17:26:32 +0000 Subject: [PATCH] Error message when the image path is wrong --- browser/main/NoteList/index.js | 2 ++ .../main/lib/dataApi/attachmentManagement.js | 27 ++++++++++++++----- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/browser/main/NoteList/index.js b/browser/main/NoteList/index.js index ed51a52e..cfcfcc99 100644 --- a/browser/main/NoteList/index.js +++ b/browser/main/NoteList/index.js @@ -923,6 +923,8 @@ class NoteList extends React.Component { .then((newcontent) => { note.content = newcontent + dataApi.updateNote(storage.key, note.key, note) + dispatch({ type: 'UPDATE_NOTE', note: note diff --git a/browser/main/lib/dataApi/attachmentManagement.js b/browser/main/lib/dataApi/attachmentManagement.js index af760e47..e47358cd 100644 --- a/browser/main/lib/dataApi/attachmentManagement.js +++ b/browser/main/lib/dataApi/attachmentManagement.js @@ -472,13 +472,28 @@ function importAttachments (markDownContent, filepath, storageKey, noteKey) { attachName = nameRegex.exec(markDownContent) } - Promise.all(promiseArray).then((fileNames) => { - for (let j = 0; j < fileNames.length; j++) { - const newPath = path.join(STORAGE_FOLDER_PLACEHOLDER, noteKey, fileNames[j]) - markDownContent = markDownContent.replace(endPath[j], newPath) - } + let numResolvedPromises = 0 + + if (promiseArray.length === 0) { resolve(markDownContent) - }) + } + + for (let j = 0; j < promiseArray.length; j++) { + promiseArray[j] + .then((fileName) => { + const newPath = path.join(STORAGE_FOLDER_PLACEHOLDER, noteKey, fileName) + markDownContent = markDownContent.replace(endPath[j], newPath) + }) + .catch((e) => { + console.error('File does not exist in path: ' + endPath[j]) + }) + .finally(() => { + numResolvedPromises++ + if (numResolvedPromises === promiseArray.length) { + resolve(markDownContent) + } + }) + } }) }