mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 17:56:25 +00:00
Fix moving note with attachments between different storage
This commit is contained in:
@@ -6,7 +6,6 @@ const CSON = require('@rokt33r/season')
|
|||||||
const keygen = require('browser/lib/keygen')
|
const keygen = require('browser/lib/keygen')
|
||||||
const sander = require('sander')
|
const sander = require('sander')
|
||||||
const { findStorage } = require('browser/lib/findStorage')
|
const { findStorage } = require('browser/lib/findStorage')
|
||||||
const copyImage = require('./copyImage')
|
|
||||||
|
|
||||||
function moveNote (storageKey, noteKey, newStorageKey, newFolderKey) {
|
function moveNote (storageKey, noteKey, newStorageKey, newFolderKey) {
|
||||||
let oldStorage, newStorage
|
let oldStorage, newStorage
|
||||||
@@ -70,16 +69,17 @@ function moveNote (storageKey, noteKey, newStorageKey, newFolderKey) {
|
|||||||
.then(function moveImages (noteData) {
|
.then(function moveImages (noteData) {
|
||||||
if (oldStorage.path === newStorage.path) return noteData
|
if (oldStorage.path === newStorage.path) return noteData
|
||||||
|
|
||||||
const searchImagesRegex = /!\[.*?]\(\s*?\/:storage\/(.*\.\S*?)\)/gi
|
const searchImagesRegex = /!\[.*\]\(:storage\/(.+)\)/gi
|
||||||
let match = searchImagesRegex.exec(noteData.content)
|
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, 'attachments', filename)
|
||||||
|
const newPath = path.join(newStorage.path, 'attachments', filename)
|
||||||
// TODO: ehhc: attachmentManagement
|
// TODO: ehhc: attachmentManagement
|
||||||
moveTasks.push(
|
moveTasks.push(
|
||||||
copyImage(oldPath, noteData.storage, false)
|
sander.copyFile(oldPath).to(newPath)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
fs.unlinkSync(oldPath)
|
fs.unlinkSync(oldPath)
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user