diff --git a/src/services/export/tar.js b/src/services/export/tar.js index 5cb6c656b..2cfadd777 100644 --- a/src/services/export/tar.js +++ b/src/services/export/tar.js @@ -250,7 +250,7 @@ ${content} if (noteMeta.isClone) { const targetUrl = getTargetUrl(noteMeta.noteId, noteMeta); - let content = `
This is a clone of a note. Go to its primary location.
`; + let content = `This is a clone of a note. Go to its primary location.
`; content = prepareContent(noteMeta.title, content, noteMeta); diff --git a/src/services/import/tar.js b/src/services/import/tar.js index 020ef4321..b59493bac 100644 --- a/src/services/import/tar.js +++ b/src/services/import/tar.js @@ -429,7 +429,11 @@ async function importTar(importContext, fileBuffer, importRootNote) { const createdNoteIds = {}; for (const path in createdPaths) { - createdNoteIds[createdPaths[path]] = true; + const noteId = createdPaths[path]; + + createdNoteIds[noteId] = true; + + await noteService.scanForLinks(noteId); } // we're saving attributes and links only now so that all relation and link target notes diff --git a/src/services/notes.js b/src/services/notes.js index 3ab688f4b..0a7642a0d 100644 --- a/src/services/notes.js +++ b/src/services/notes.js @@ -271,6 +271,11 @@ async function saveLinks(note, content) { const existingLinks = await note.getLinks(); for (const foundLink of foundLinks) { + const targetNote = await repository.getNote(foundLink.value); + if (!targetNote || targetNote.isDeleted) { + continue; + } + const existingLink = existingLinks.find(existingLink => existingLink.value === foundLink.value && existingLink.name === foundLink.name); @@ -422,6 +427,18 @@ async function deleteNote(branch) { } } +async function scanForLinks(noteId) { + const note = await repository.getNote(noteId); + if (!note || !['text', 'relation-map'].includes(note.type)) { + return; + } + + const content = await note.getContent(); + const newContent = await saveLinks(note, content); + + await note.setContent(newContent); +} + async function cleanupDeletedNotes() { const cutoffDate = new Date(Date.now() - 48 * 3600 * 1000); @@ -445,5 +462,6 @@ module.exports = { createNote, updateNote, deleteNote, - protectNoteRecursively + protectNoteRecursively, + scanForLinks }; \ No newline at end of file