trilium/src/entities/note_revision.js

52 lines
1.5 KiB
JavaScript
Raw Normal View History

"use strict";
const Entity = require('./entity');
const protectedSessionService = require('../services/protected_session');
const repository = require('../services/repository');
2018-08-23 05:37:06 +08:00
/**
* NoteRevision represents snapshot of note's title and content at some point in the past. It's used for seamless note versioning.
*
* @param {string} noteRevisionId
* @param {string} noteId
* @param {string} type
* @param {string} mime
* @param {string} title
* @param {string} content
* @param {string} isProtected
* @param {string} dateModifiedFrom
* @param {string} dateModifiedTo
2019-03-13 03:58:31 +08:00
* @param {string} utcDateModifiedFrom
* @param {string} utcDateModifiedTo
2018-08-23 05:37:06 +08:00
*
* @extends Entity
*/
class NoteRevision extends Entity {
static get entityName() { return "note_revisions"; }
2018-01-31 09:12:19 +08:00
static get primaryKeyName() { return "noteRevisionId"; }
static get hashedProperties() { return ["noteRevisionId", "noteId", "title", "content", "isProtected", "dateModifiedFrom", "dateModifiedTo", "utcDateModifiedFrom", "utcDateModifiedTo"]; }
2018-01-30 12:35:36 +08:00
constructor(row) {
super(row);
this.isProtected = !!this.isProtected;
if (this.isProtected) {
protectedSessionService.decryptNoteRevision(this);
}
}
async getNote() {
return await repository.getEntity("SELECT * FROM notes WHERE noteId = ?", [this.noteId]);
}
beforeSaving() {
if (this.isProtected) {
protectedSessionService.encryptNoteRevision(this);
}
super.beforeSaving();
}
}
module.exports = NoteRevision;