mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 01:36:22 +00:00
Attachment management should only become active on cloning notes if the note was of type MARKDOWN_NOTE -> No Stacktraces otherwise!
This commit is contained in:
@@ -288,20 +288,24 @@ function deleteAttachmentsNotPresentInNote (markdownContent, storageKey, noteKey
|
||||
* @param newNote Clone of the note
|
||||
*/
|
||||
function cloneAttachments (oldNote, newNote) {
|
||||
const oldStorage = findStorage.findStorage(oldNote.storage)
|
||||
const newStorage = findStorage.findStorage(newNote.storage)
|
||||
const attachmentsPaths = getAbsolutePathsOfAttachmentsInContent(oldNote.content, oldStorage.path) || []
|
||||
if (newNote.type === 'MARKDOWN_NOTE') {
|
||||
const oldStorage = findStorage.findStorage(oldNote.storage)
|
||||
const newStorage = findStorage.findStorage(newNote.storage)
|
||||
const attachmentsPaths = getAbsolutePathsOfAttachmentsInContent(oldNote.content, oldStorage.path) || []
|
||||
|
||||
const destinationFolder = path.join(newStorage.path, DESTINATION_FOLDER, newNote.key)
|
||||
if (!sander.existsSync(destinationFolder)) {
|
||||
sander.mkdirSync(destinationFolder)
|
||||
}
|
||||
const destinationFolder = path.join(newStorage.path, DESTINATION_FOLDER, newNote.key)
|
||||
if (!sander.existsSync(destinationFolder)) {
|
||||
sander.mkdirSync(destinationFolder)
|
||||
}
|
||||
|
||||
for (const attachment of attachmentsPaths) {
|
||||
const destination = path.join(newStorage.path, DESTINATION_FOLDER, newNote.key, path.basename(attachment))
|
||||
sander.copyFileSync(attachment).to(destination)
|
||||
for (const attachment of attachmentsPaths) {
|
||||
const destination = path.join(newStorage.path, DESTINATION_FOLDER, newNote.key, path.basename(attachment))
|
||||
sander.copyFileSync(attachment).to(destination)
|
||||
}
|
||||
newNote.content = replaceNoteKeyWithNewNoteKey(newNote.content, oldNote.key, newNote.key)
|
||||
} else {
|
||||
console.debug('Cloning of the attachment was skipped since it only works for MARKDOWN_NOTEs')
|
||||
}
|
||||
newNote.content = replaceNoteKeyWithNewNoteKey(newNote.content, oldNote.key, newNote.key)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
||||
@@ -396,8 +396,8 @@ it('should test that moveAttachments returns a correct modified content version'
|
||||
})
|
||||
|
||||
it('should test that cloneAttachments modifies the content of the new note correctly', function () {
|
||||
const oldNote = {key: 'oldNoteKey', content: 'oldNoteContent', storage: 'storageKey'}
|
||||
const newNote = {key: 'newNoteKey', content: 'oldNoteContent', storage: 'storageKey'}
|
||||
const oldNote = {key: 'oldNoteKey', content: 'oldNoteContent', storage: 'storageKey', type: 'MARKDOWN_NOTE'}
|
||||
const newNote = {key: 'newNoteKey', content: 'oldNoteContent', storage: 'storageKey', type: 'MARKDOWN_NOTE'}
|
||||
const testInput =
|
||||
'Test input' +
|
||||
' \n' +
|
||||
@@ -418,8 +418,8 @@ it('should test that cloneAttachments finds all attachments and copies them to t
|
||||
const storagePathNew = 'storagePathNew'
|
||||
const dummyStorageOld = {path: storagePathOld}
|
||||
const dummyStorageNew = {path: storagePathNew}
|
||||
const oldNote = {key: 'oldNoteKey', content: 'oldNoteContent', storage: 'storageKeyOldNote'}
|
||||
const newNote = {key: 'newNoteKey', content: 'oldNoteContent', storage: 'storageKeyNewNote'}
|
||||
const oldNote = {key: 'oldNoteKey', content: 'oldNoteContent', storage: 'storageKeyOldNote', type: 'MARKDOWN_NOTE'}
|
||||
const newNote = {key: 'newNoteKey', content: 'oldNoteContent', storage: 'storageKeyNewNote', type: 'MARKDOWN_NOTE'}
|
||||
const testInput =
|
||||
'Test input' +
|
||||
' \n' +
|
||||
@@ -451,3 +451,19 @@ it('should test that cloneAttachments finds all attachments and copies them to t
|
||||
expect(sander.copyFileSync.mock.calls[1][0]).toBe(pathAttachmentTwoFrom)
|
||||
expect(copyFileSyncResp.to.mock.calls[1][0]).toBe(pathAttachmentTwoTo)
|
||||
})
|
||||
|
||||
it('should test that cloneAttachments finds all attachments and copies them to the new location', function () {
|
||||
const oldNote = {key: 'oldNoteKey', content: 'oldNoteContent', storage: 'storageKeyOldNote', type: 'SOMETHING_ELSE'}
|
||||
const newNote = {key: 'newNoteKey', content: 'oldNoteContent', storage: 'storageKeyNewNote', type: 'SOMETHING_ELSE'}
|
||||
const testInput = 'Test input'
|
||||
oldNote.content = testInput
|
||||
newNote.content = testInput
|
||||
|
||||
sander.copyFileSync = jest.fn()
|
||||
findStorage.findStorage = jest.fn()
|
||||
|
||||
systemUnderTest.cloneAttachments(oldNote, newNote)
|
||||
|
||||
expect(findStorage.findStorage).not.toHaveBeenCalled()
|
||||
expect(sander.copyFileSync).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user