mirror of
https://github.com/zadam/trilium.git
synced 2025-11-18 03:00:41 +01:00
split out note's content into separate entity, WIP
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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`,
|
||||
|
||||
@@ -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
|
||||
};
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user