mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 09:46:22 +00:00
Reduced nests
This commit is contained in:
@@ -68,29 +68,27 @@ function moveNote (storageKey, noteKey, newStorageKey, newFolderKey) {
|
|||||||
return noteData
|
return noteData
|
||||||
})
|
})
|
||||||
.then(function moveImages (noteData) {
|
.then(function moveImages (noteData) {
|
||||||
if (oldStorage.path === newStorage.path) {
|
if (oldStorage.path === newStorage.path) return noteData
|
||||||
return noteData
|
|
||||||
} else {
|
|
||||||
const searchImagesRegex = /!\[.*?]\(\s*?\/:storage\/(.*\.\S*?)\)/gi
|
|
||||||
let match = searchImagesRegex.exec(noteData.content)
|
|
||||||
|
|
||||||
const moveTasks = []
|
const searchImagesRegex = /!\[.*?]\(\s*?\/:storage\/(.*\.\S*?)\)/gi
|
||||||
while (match != null) {
|
let match = searchImagesRegex.exec(noteData.content)
|
||||||
const [, filename] = match
|
|
||||||
const oldPath = path.join(oldStorage.path, 'images', filename)
|
|
||||||
moveTasks.push(
|
|
||||||
copyImage(oldPath, noteData.storage, false)
|
|
||||||
.then(() => {
|
|
||||||
fs.unlinkSync(oldPath)
|
|
||||||
})
|
|
||||||
)
|
|
||||||
|
|
||||||
// find next occurence
|
const moveTasks = []
|
||||||
match = searchImagesRegex.exec(noteData.content)
|
while (match != null) {
|
||||||
}
|
const [, filename] = match
|
||||||
|
const oldPath = path.join(oldStorage.path, 'images', filename)
|
||||||
|
moveTasks.push(
|
||||||
|
copyImage(oldPath, noteData.storage, false)
|
||||||
|
.then(() => {
|
||||||
|
fs.unlinkSync(oldPath)
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
return Promise.all(moveTasks).then(() => noteData)
|
// find next occurence
|
||||||
|
match = searchImagesRegex.exec(noteData.content)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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']))
|
||||||
|
|||||||
Reference in New Issue
Block a user