fix saving note revisions, closes #2915

This commit is contained in:
zadam 2022-06-13 22:54:08 +02:00
parent 23e9bcfdc5
commit df3fdb59c5
6 changed files with 15 additions and 7 deletions

View File

@ -280,7 +280,7 @@ function isHtmlEmpty(html) {
async function clearBrowserCache() { async function clearBrowserCache() {
if (isElectron()) { if (isElectron()) {
const win = utils.dynamicRequire('@electron/remote').getCurrentWindow(); const win = dynamicRequire('@electron/remote').getCurrentWindow();
await win.webContents.session.clearCache(); await win.webContents.session.clearCache();
} }
} }

View File

@ -21,7 +21,8 @@ function updateFile(req) {
return [404, `Note ${noteId} doesn't exist.`]; return [404, `Note ${noteId} doesn't exist.`];
} }
noteRevisionService.createNoteRevision(note); note.saveNoteRevision();
noteRevisionService.protectNoteRevisions(note);
note.mime = file.mimetype.toLowerCase(); note.mime = file.mimetype.toLowerCase();
note.save(); note.save();

View File

@ -97,7 +97,8 @@ function restoreNoteRevision(req) {
if (noteRevision) { if (noteRevision) {
const note = noteRevision.getNote(); const note = noteRevision.getNote();
noteRevisionService.createNoteRevision(note); note.saveNoteRevision();
noteRevisionService.protectNoteRevisions(note);
note.title = noteRevision.title; note.title = noteRevision.title;
note.setContent(noteRevision.getContent()); note.setContent(noteRevision.getContent());

View File

@ -294,7 +294,8 @@ function uploadModifiedFile(req) {
log.info(`Updating note '${noteId}' with content from ${filePath}`); log.info(`Updating note '${noteId}' with content from ${filePath}`);
noteRevisionService.createNoteRevision(note); note.saveNoteRevision();
noteRevisionService.protectNoteRevisions(note);
const fileContent = fs.readFileSync(filePath); const fileContent = fs.readFileSync(filePath);

View File

@ -68,7 +68,7 @@ function updateImage(noteId, uploadBuffer, originalName) {
const note = becca.getNote(noteId); const note = becca.getNote(noteId);
noteRevisionService.createNoteRevision(note); note.saveNoteRevision();
noteRevisionService.protectNoteRevisions(note); noteRevisionService.protectNoteRevisions(note);
note.setLabel('originalFileName', originalName); note.setLabel('originalFileName', originalName);

View File

@ -1,9 +1,8 @@
"use strict"; "use strict";
const NoteRevision = require('../becca/entities/note_revision');
const dateUtils = require('./date_utils');
const log = require('./log'); const log = require('./log');
const sql = require('./sql'); const sql = require('./sql');
const protectedSession = require("./protected_session");
/** /**
* @param {Note} note * @param {Note} note
@ -11,6 +10,12 @@ const sql = require('./sql');
function protectNoteRevisions(note) { function protectNoteRevisions(note) {
for (const revision of note.getNoteRevisions()) { for (const revision of note.getNoteRevisions()) {
if (note.isProtected !== revision.isProtected) { if (note.isProtected !== revision.isProtected) {
if (!protectedSession.isProtectedSessionAvailable()) {
log.error("Protected session is not available to fix note revisions.");
return;
}
try { try {
const content = revision.getContent(); const content = revision.getContent();