1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 01:36:22 +00:00

absolute path

This commit is contained in:
anasasilva
2018-12-16 15:10:19 +00:00
committed by Junyoung Choi
parent 7106f042da
commit 9d47f319a0

View File

@@ -458,17 +458,15 @@ function getAbsolutePathsOfAttachmentsInContent (markdownContent, storagePath) {
*/
function importAttachments (markDownContent, filepath, storageKey, noteKey) {
return new Promise((resolve, reject) => {
const nameRegex = /(!\[.*?]\()(.+?\..+?)(\))/g
const nameRegex = /(!\[.+?]\()(.+?\..+?)(\))/g
let attachName = nameRegex.exec(markDownContent)
const promiseArray = []
const beginPath = filepath.match(/\/.+\//)[0]
const endPath = []
const attachPath = []
const groupIndex = 2
while (attachName) {
endPath.push(attachName[groupIndex])
const finalPath = path.join(beginPath, attachName[groupIndex])
promiseArray.push(this.copyAttachment(finalPath, storageKey, noteKey))
attachPath.push(attachName[groupIndex])
promiseArray.push(this.copyAttachment(attachName[groupIndex], storageKey, noteKey))
attachName = nameRegex.exec(markDownContent)
}
@@ -482,10 +480,10 @@ function importAttachments (markDownContent, filepath, storageKey, noteKey) {
promiseArray[j]
.then((fileName) => {
const newPath = path.join(STORAGE_FOLDER_PLACEHOLDER, noteKey, fileName)
markDownContent = markDownContent.replace(endPath[j], newPath)
markDownContent = markDownContent.replace(attachPath[j], newPath)
})
.catch((e) => {
console.error('File does not exist in path: ' + endPath[j])
console.error('File does not exist in path: ' + attachPath[j])
})
.finally(() => {
numResolvedPromises++