Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fixes in import & export related to the protected session
zadam15a2fe25705b
diff --git a/src/routes/api/similar_notes.js b/src/routes/api/similar_notes.jsindex b84589e6fd..3403833f88 100644--- a/src/routes/api/similar_notes.js+++ b/src/routes/api/similar_notes.js@@ -12,12 +12,8 @@ async function getSimilarNotes(req) {return [404, `Note ${noteId} not found.`];}- const start = new Date();-const results = await noteCacheService.findSimilarNotes(note.title);- console.log("Similar note took: " + (Date.now() - start.getTime()) + "ms");-return results.filter(note => note.noteId !== noteId);}diff --git a/src/services/export/tar.js b/src/services/export/tar.jsindex 2cfadd7773..d09e3429b7 100644--- a/src/services/export/tar.js+++ b/src/services/export/tar.js@@ -8,7 +8,7 @@ const mimeTypes = require('mime-types');const TurndownService = require('turndown');const packageInfo = require('../../../package.json');const utils = require('../utils');-const log = require('../log');+const protectedSessionService = require('../protected_session');const sanitize = require("sanitize-filename");/**@@ -136,8 +136,10 @@ async function exportToTar(exportContext, branch, format, res) {const childBranches = await note.getChildBranches();+ const available = !note.isProtected || protectedSessionService.isProtectedSessionAvailable();+// if it's a leaf then we'll export it even if it's empty- if ((await note.getContent()).length > 0 || childBranches.length === 0) {+ if (available && ((await note.getContent()).length > 0 || childBranches.length === 0)) {meta.dataFileName = getDataFileName(note, baseFileName, existingFileNames);}diff --git a/src/services/import/tar.js b/src/services/import/tar.jsindex b59493bac7..64a70e0b7a 100644--- a/src/services/import/tar.js+++ b/src/services/import/tar.js@@ -238,8 +238,6 @@ async function importTar(importContext, fileBuffer, importRootNote) {absUrl += (absUrl.length > 0 ? '/' : '') + url;- console.log("absUrl", absUrl);-const targetNoteId = getNoteId(null, absUrl);return targetNoteId;}@@ -434,6 +432,8 @@ async function importTar(importContext, fileBuffer, importRootNote) {createdNoteIds[noteId] = true;await noteService.scanForLinks(noteId);++ importContext.increaseProgressCount();}// we're saving attributes and links only now so that all relation and link target notesdiff --git a/src/services/notes.js b/src/services/notes.jsindex f27049554d..f6c81040a9 100644--- a/src/services/notes.js+++ b/src/services/notes.js@@ -12,6 +12,8 @@ const NoteRevision = require('../entities/note_revision');const Branch = require('../entities/branch');const Attribute = require('../entities/attribute');const hoistedNoteService = require('../services/hoisted_note');+const protectedSessionService = require('../services/protected_session');+const log = require('../services/log');async function getNewNotePosition(parentNoteId, noteData) {let newNotePos = 0;@@ -255,6 +257,10 @@ async function saveLinks(note, content) {return content;}+ if (note.isProtected && !protectedSessionService.isProtectedSessionAvailable()) {+ return content;+ }+const foundLinks = [];if (note.type === 'text') {@@ -433,10 +439,15 @@ async function scanForLinks(noteId) {return;}- const content = await note.getContent();- const newContent = await saveLinks(note, content);+ try {+ const content = await note.getContent();+ const newContent = await saveLinks(note, content);- await note.setContent(newContent);+ await note.setContent(newContent);+ }+ catch (e) {+ log.error(`Could not scan for links note ${noteId}: ${e.message}`);+ }}async function cleanupDeletedNotes() {