mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 17:56:25 +00:00
Supports relative and absolute path
This commit is contained in:
committed by
Junyoung Choi
parent
3d6f670e8d
commit
c474d972cb
@@ -459,15 +459,21 @@ function getAbsolutePathsOfAttachmentsInContent (markdownContent, storagePath) {
|
|||||||
function importAttachments (markDownContent, filepath, storageKey, noteKey) {
|
function importAttachments (markDownContent, filepath, storageKey, noteKey) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const nameRegex = /(!\[.*?]\()(.+?\..+?)(\))/g
|
const nameRegex = /(!\[.*?]\()(.+?\..+?)(\))/g
|
||||||
let attachName = nameRegex.exec(markDownContent)
|
let attachPath = nameRegex.exec(markDownContent)
|
||||||
const promiseArray = []
|
const promiseArray = []
|
||||||
const attachPath = []
|
const attachmentPaths = []
|
||||||
const groupIndex = 2
|
const groupIndex = 2
|
||||||
|
|
||||||
while (attachName) {
|
while (attachPath) {
|
||||||
attachPath.push(attachName[groupIndex])
|
attachmentPaths.push(attachPath[groupIndex])
|
||||||
promiseArray.push(this.copyAttachment(attachName[groupIndex], storageKey, noteKey))
|
|
||||||
attachName = nameRegex.exec(markDownContent)
|
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
|
let numResolvedPromises = 0
|
||||||
@@ -480,10 +486,10 @@ function importAttachments (markDownContent, filepath, storageKey, noteKey) {
|
|||||||
promiseArray[j]
|
promiseArray[j]
|
||||||
.then((fileName) => {
|
.then((fileName) => {
|
||||||
const newPath = path.join(STORAGE_FOLDER_PLACEHOLDER, noteKey, fileName)
|
const newPath = path.join(STORAGE_FOLDER_PLACEHOLDER, noteKey, fileName)
|
||||||
markDownContent = markDownContent.replace(attachPath[j], newPath)
|
markDownContent = markDownContent.replace(attachmentPaths[j], newPath)
|
||||||
})
|
})
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
console.error('File does not exist in path: ' + attachPath[j])
|
console.error('File does not exist in path: ' + attachmentPaths[j])
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
numResolvedPromises++
|
numResolvedPromises++
|
||||||
|
|||||||
Reference in New Issue
Block a user