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

Supports relative and absolute path

This commit is contained in:
anasasilva
2018-12-19 10:26:29 +00:00
committed by Junyoung Choi
parent 3d6f670e8d
commit c474d972cb

View File

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