mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
fixed update of encrypted note
This commit is contained in:
parent
b2338c31d7
commit
53d327e435
@ -42,7 +42,7 @@
|
|||||||
<div style="float: left; margin: 0 5px 5px 5px;" class="hide-toggle">
|
<div style="float: left; margin: 0 5px 5px 5px;" class="hide-toggle">
|
||||||
<input autocomplete="off" value="Welcome to Notecase web app!" id="noteTitle" style="font-size: x-large; border: 0; width: 600px;" tabindex="1">
|
<input autocomplete="off" value="Welcome to Notecase web app!" id="noteTitle" style="font-size: x-large; border: 0; width: 600px;" tabindex="1">
|
||||||
|
|
||||||
<button class="btn btn-sm" onclick="encryptNote();">Encrypt</button>
|
<button class="btn btn-sm" onclick="encryptNoteAndSendToServer();">Encrypt</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div style="clear: both; height: 0"></div>
|
<div style="clear: both; height: 0"></div>
|
||||||
|
@ -67,7 +67,9 @@ function saveNoteIfChanged(callback) {
|
|||||||
|
|
||||||
updateNoteFromInputs(note);
|
updateNoteFromInputs(note);
|
||||||
|
|
||||||
saveNoteToServer(note, callback);
|
encryptNoteIfNecessary(note).then(note => {
|
||||||
|
saveNoteToServer(note, callback);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
setInterval(saveNoteIfChanged, 5000);
|
setInterval(saveNoteIfChanged, 5000);
|
||||||
@ -160,16 +162,7 @@ function loadNote(noteId) {
|
|||||||
$("#noteTitle").focus().select();
|
$("#noteTitle").focus().select();
|
||||||
}
|
}
|
||||||
|
|
||||||
let decryptPromise;
|
decryptNoteIfNecessary(note).then(decrypted => {
|
||||||
|
|
||||||
if (note.detail.encryption === 1) {
|
|
||||||
decryptPromise = decryptNote(note.detail.note_text);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
decryptPromise = Promise.resolve(note.detail.note_text);
|
|
||||||
}
|
|
||||||
|
|
||||||
decryptPromise.then(decrypted => {
|
|
||||||
note.detail.note_text = decrypted;
|
note.detail.note_text = decrypted;
|
||||||
|
|
||||||
let noteText = notecase2html(note);
|
let noteText = notecase2html(note);
|
||||||
@ -262,12 +255,17 @@ function getAes() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function encryptNote() {
|
function encryptNoteIfNecessary(note) {
|
||||||
getAes().then(aes => {
|
if (note.detail.encryption === 0) {
|
||||||
const note = globalNote;
|
return Promise.resolve(note);
|
||||||
|
}
|
||||||
updateNoteFromInputs(note);
|
else {
|
||||||
|
return encryptNote(note);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function encryptNote(note) {
|
||||||
|
return getAes().then(aes => {
|
||||||
const noteJson = note.detail.note_text;
|
const noteJson = note.detail.note_text;
|
||||||
|
|
||||||
const noteBytes = aesjs.utils.utf8.toBytes(noteJson);
|
const noteBytes = aesjs.utils.utf8.toBytes(noteJson);
|
||||||
@ -275,9 +273,16 @@ function encryptNote() {
|
|||||||
const encryptedBytes = aes.encrypt(noteBytes);
|
const encryptedBytes = aes.encrypt(noteBytes);
|
||||||
|
|
||||||
// To print or store the binary data, you may convert it to hex
|
// To print or store the binary data, you may convert it to hex
|
||||||
const encryptedBase64 = uint8ToBase64(encryptedBytes);
|
note.detail.note_text = uint8ToBase64(encryptedBytes);
|
||||||
|
|
||||||
note.detail.note_text = encryptedBase64;
|
return note;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function encryptNoteAndSendToServer() {
|
||||||
|
updateNoteFromInputs(globalNote);
|
||||||
|
|
||||||
|
encryptNote(globalNote).then(note => {
|
||||||
note.detail.encryption = 1;
|
note.detail.encryption = 1;
|
||||||
|
|
||||||
saveNoteToServer(note);
|
saveNoteToServer(note);
|
||||||
@ -286,6 +291,18 @@ function encryptNote() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function decryptNoteIfNecessary(note) {
|
||||||
|
let decryptPromise;
|
||||||
|
|
||||||
|
if (note.detail.encryption === 1) {
|
||||||
|
decryptPromise = decryptNote(note.detail.note_text);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
decryptPromise = Promise.resolve(note.detail.note_text);
|
||||||
|
}
|
||||||
|
return decryptPromise;
|
||||||
|
}
|
||||||
|
|
||||||
function decryptNote(encryptedBase64) {
|
function decryptNote(encryptedBase64) {
|
||||||
return getAes().then(aes => {
|
return getAes().then(aes => {
|
||||||
const encryptedBytes = base64ToUint8Array(encryptedBase64);
|
const encryptedBytes = base64ToUint8Array(encryptedBase64);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user