1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 17:56:25 +00:00

Fixed moving notes with images

This commit is contained in:
Frank Kanis
2018-04-12 21:20:16 +02:00
parent 4b9cf775ff
commit 7aedb59f26

View File

@@ -68,26 +68,30 @@ function moveNote (storageKey, noteKey, newStorageKey, newFolderKey) {
return noteData return noteData
}) })
.then(function moveImages (noteData) { .then(function moveImages (noteData) {
const searchImagesRegex = /!\[.*?]\(\s*?\/:storage\/(.*\.\S*?)\)/gi if(oldStorage.path === newStorage.path) {
let match = searchImagesRegex.exec(noteData.content) return noteData
} else {
const searchImagesRegex = /!\[.*?]\(\s*?\/:storage\/(.*\.\S*?)\)/gi
let match = searchImagesRegex.exec(noteData.content)
const moveTasks = [] const moveTasks = []
while (match != null) { while (match != null) {
const [, filename] = match const [, filename] = match
const oldPath = path.join(oldStorage.path, 'images', filename) const oldPath = path.join(oldStorage.path, 'images', filename)
moveTasks.push( moveTasks.push(
copyImage(oldPath, noteData.storage, false) copyImage(oldPath, noteData.storage, false)
.then(() => { .then(() => {
fs.unlinkSync(oldPath) fs.unlinkSync(oldPath)
}) })
) )
// find next occurence // find next occurence
match = searchImagesRegex.exec(noteData.content) match = searchImagesRegex.exec(noteData.content)
} }
return Promise.all(moveTasks).then(() => noteData) return Promise.all(moveTasks).then(() => noteData)
}) }
})
.then(function writeAndReturn (noteData) { .then(function writeAndReturn (noteData) {
CSON.writeFileSync(path.join(newStorage.path, 'notes', noteData.key + '.cson'), _.omit(noteData, ['key', 'storage'])) CSON.writeFileSync(path.join(newStorage.path, 'notes', noteData.key + '.cson'), _.omit(noteData, ['key', 'storage']))
return noteData return noteData