split out note's content into separate entity, WIP

This commit is contained in:
zadam
2019-02-06 20:19:25 +01:00
parent 8b250ed523
commit 8884177d9f
18 changed files with 417 additions and 213 deletions

View File

@@ -4,8 +4,8 @@ const build = require('./build');
const packageJson = require('../../package');
const {TRILIUM_DATA_DIR} = require('./data_dir');
const APP_DB_VERSION = 124;
const SYNC_VERSION = 4;
const APP_DB_VERSION = 125;
const SYNC_VERSION = 5;
module.exports = {
appVersion: packageJson.version,

View File

@@ -234,6 +234,7 @@ async function findLogicIssues() {
await findIssues(`
SELECT noteId
FROM notes
JOIN note_contents USING(noteId)
WHERE
isDeleted = 0
AND content IS NULL`,

View File

@@ -47,28 +47,25 @@ function decryptNoteTitle(noteId, encryptedTitle) {
}
function decryptNote(note) {
const dataKey = getDataKey();
if (!note.isProtected) {
return;
}
try {
if (note.title) {
note.title = dataEncryptionService.decryptString(dataKey, note.title);
}
if (note.title) {
note.title = decryptNoteTitle(note.noteId)
}
}
if (note.content) {
if (note.type === 'file' || note.type === 'image') {
note.content = dataEncryptionService.decrypt(dataKey, note.content);
}
else {
note.content = dataEncryptionService.decryptString(dataKey, note.content);
}
}
function decryptNoteContent(noteContent) {
if (!noteContent.isProtected) {
return;
}
try {
noteContent.content = dataEncryptionService.decrypt(getDataKey(), noteContent.content);
}
catch (e) {
e.message = `Cannot decrypt note for noteId=${note.noteId}: ` + e.message;
e.message = `Cannot decrypt note content for noteContentId=${noteContent.noteContentId}: ` + e.message;
throw e;
}
}
@@ -96,10 +93,11 @@ function decryptNoteRevision(hist) {
}
function encryptNote(note) {
const dataKey = getDataKey();
note.title = dataEncryptionService.encrypt(getDataKey(), note.title);
}
note.title = dataEncryptionService.encrypt(dataKey, note.title);
note.content = dataEncryptionService.encrypt(dataKey, note.content);
function encryptNoteContent(noteContent) {
noteContent.content = dataEncryptionService.encrypt(getDataKey(), noteContent.content);
}
function encryptNoteRevision(revision) {
@@ -115,9 +113,11 @@ module.exports = {
isProtectedSessionAvailable,
decryptNoteTitle,
decryptNote,
decryptNoteContent,
decryptNotes,
decryptNoteRevision,
encryptNote,
encryptNoteContent,
encryptNoteRevision,
setProtectedSessionId
};

View File

@@ -37,27 +37,32 @@ async function getEntity(query, params = []) {
return entityConstructor.createEntityFromRow(row);
}
/** @returns {Note|null} */
/** @returns {Promise<Note|null>} */
async function getNote(noteId) {
return await getEntity("SELECT * FROM notes WHERE noteId = ?", [noteId]);
}
/** @returns {Branch|null} */
/** @returns {Promise<NoteContent|null>} */
async function getNoteContent(noteContentId) {
return await getEntity("SELECT * FROM note_contents WHERE noteContentId = ?", [noteContentId]);
}
/** @returns {Promise<Branch|null>} */
async function getBranch(branchId) {
return await getEntity("SELECT * FROM branches WHERE branchId = ?", [branchId]);
}
/** @returns {Attribute|null} */
/** @returns {Promise<Attribute|null>} */
async function getAttribute(attributeId) {
return await getEntity("SELECT * FROM attributes WHERE attributeId = ?", [attributeId]);
}
/** @returns {Option|null} */
/** @returns {Promise<Option|null>} */
async function getOption(name) {
return await getEntity("SELECT * FROM options WHERE name = ?", [name]);
}
/** @returns {Link|null} */
/** @returns {Promise<Link|null>} */
async function getLink(linkId) {
return await getEntity("SELECT * FROM links WHERE linkId = ?", [linkId]);
}
@@ -121,6 +126,7 @@ module.exports = {
getEntities,
getEntity,
getNote,
getNoteContent,
getBranch,
getAttribute,
getOption,