mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 18:36:30 +01:00 
			
		
		
		
	fixes in import & export related to the protected session
This commit is contained in:
		| @@ -12,12 +12,8 @@ async function getSimilarNotes(req) { | |||||||
|         return [404, `Note ${noteId} not found.`]; |         return [404, `Note ${noteId} not found.`]; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     const start = new Date(); |  | ||||||
|  |  | ||||||
|     const results = await noteCacheService.findSimilarNotes(note.title); |     const results = await noteCacheService.findSimilarNotes(note.title); | ||||||
|  |  | ||||||
|     console.log("Similar note took: " + (Date.now() - start.getTime()) + "ms"); |  | ||||||
|  |  | ||||||
|     return results |     return results | ||||||
|         .filter(note => note.noteId !== noteId); |         .filter(note => note.noteId !== noteId); | ||||||
| } | } | ||||||
|   | |||||||
| @@ -8,7 +8,7 @@ const mimeTypes = require('mime-types'); | |||||||
| const TurndownService = require('turndown'); | const TurndownService = require('turndown'); | ||||||
| const packageInfo = require('../../../package.json'); | const packageInfo = require('../../../package.json'); | ||||||
| const utils = require('../utils'); | const utils = require('../utils'); | ||||||
| const log = require('../log'); | const protectedSessionService = require('../protected_session'); | ||||||
| const sanitize = require("sanitize-filename"); | const sanitize = require("sanitize-filename"); | ||||||
|  |  | ||||||
| /** | /** | ||||||
| @@ -136,8 +136,10 @@ async function exportToTar(exportContext, branch, format, res) { | |||||||
|  |  | ||||||
|         const childBranches = await note.getChildBranches(); |         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 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); |             meta.dataFileName = getDataFileName(note, baseFileName, existingFileNames); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -238,8 +238,6 @@ async function importTar(importContext, fileBuffer, importRootNote) { | |||||||
|  |  | ||||||
|         absUrl += (absUrl.length > 0 ? '/' : '') + url; |         absUrl += (absUrl.length > 0 ? '/' : '') + url; | ||||||
|  |  | ||||||
|         console.log("absUrl", absUrl); |  | ||||||
|  |  | ||||||
|         const targetNoteId = getNoteId(null, absUrl); |         const targetNoteId = getNoteId(null, absUrl); | ||||||
|         return targetNoteId; |         return targetNoteId; | ||||||
|     } |     } | ||||||
| @@ -434,6 +432,8 @@ async function importTar(importContext, fileBuffer, importRootNote) { | |||||||
|                 createdNoteIds[noteId] = true; |                 createdNoteIds[noteId] = true; | ||||||
|  |  | ||||||
|                 await noteService.scanForLinks(noteId); |                 await noteService.scanForLinks(noteId); | ||||||
|  |  | ||||||
|  |                 importContext.increaseProgressCount(); | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             // we're saving attributes and links only now so that all relation and link target notes |             // we're saving attributes and links only now so that all relation and link target notes | ||||||
|   | |||||||
| @@ -12,6 +12,8 @@ const NoteRevision = require('../entities/note_revision'); | |||||||
| const Branch = require('../entities/branch'); | const Branch = require('../entities/branch'); | ||||||
| const Attribute = require('../entities/attribute'); | const Attribute = require('../entities/attribute'); | ||||||
| const hoistedNoteService = require('../services/hoisted_note'); | const hoistedNoteService = require('../services/hoisted_note'); | ||||||
|  | const protectedSessionService = require('../services/protected_session'); | ||||||
|  | const log = require('../services/log'); | ||||||
|  |  | ||||||
| async function getNewNotePosition(parentNoteId, noteData) { | async function getNewNotePosition(parentNoteId, noteData) { | ||||||
|     let newNotePos = 0; |     let newNotePos = 0; | ||||||
| @@ -255,6 +257,10 @@ async function saveLinks(note, content) { | |||||||
|         return content; |         return content; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     if (note.isProtected && !protectedSessionService.isProtectedSessionAvailable()) { | ||||||
|  |         return content; | ||||||
|  |     } | ||||||
|  |  | ||||||
|     const foundLinks = []; |     const foundLinks = []; | ||||||
|  |  | ||||||
|     if (note.type === 'text') { |     if (note.type === 'text') { | ||||||
| @@ -433,10 +439,15 @@ async function scanForLinks(noteId) { | |||||||
|         return; |         return; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     try { | ||||||
|         const content = await note.getContent(); |         const content = await note.getContent(); | ||||||
|         const newContent = await saveLinks(note, content); |         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() { | async function cleanupDeletedNotes() { | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user