fixes in import & export related to the protected session

This commit is contained in:
zadam 2019-09-01 22:09:55 +02:00
parent 8dadc7e518
commit 15a2fe2570
4 changed files with 20 additions and 11 deletions

View file

@ -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);
}

View file

@ -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);
}

View file

@ -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 notes

View file

@ -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,11 +439,16 @@ async function scanForLinks(noteId) {
return;
}
try {
const content = await note.getContent();
const newContent = await saveLinks(note, content);
await note.setContent(newContent);
}
catch (e) {
log.error(`Could not scan for links note ${noteId}: ${e.message}`);
}
}
async function cleanupDeletedNotes() {
const cutoffDate = new Date(Date.now() - 48 * 3600 * 1000);