1
1
Fork 0
mirror of https://github.com/zadam/trilium.git synced 2025-02-22 05:56:03 +08:00

also de-encryption of note history plus bug fixes

This commit is contained in:
azivner 2017-11-02 23:55:22 -04:00
parent 471f7c669d
commit ac0e5ada6e
2 changed files with 19 additions and 9 deletions
public/javascripts
routes/api

View file

@ -235,31 +235,39 @@ function encryptNoteAndSendToServer() {
saveNoteToServer(note);
encryptNoteHistory(note.detail.note_id);
changeEncryptionOnNoteHistory(note.detail.note_id, true);
setNoteBackgroundIfEncrypted(note);
});
}
function encryptNoteHistory(noteId) {
function changeEncryptionOnNoteHistory(noteId, encrypt) {
$.ajax({
url: baseApiUrl + 'notes-history/' + noteId + "?encryption=0",
url: baseApiUrl + 'notes-history/' + noteId + "?encryption=" + (encrypt ? 0 : 1),
type: 'GET',
success: result => {
for (const row of result) {
row.note_title = encryptString(row.note_title);
row.note_text = encryptString(row.note_text);
if (encrypt) {
row.note_title = encryptString(row.note_title);
row.note_text = encryptString(row.note_text);
}
else {
row.note_title = decryptString(row.note_title);
row.note_text = decryptString(row.note_text);
}
row.encryption = 1;
row.encryption = encrypt ? 1 : 0;
$.ajax({
url: baseApiUrl + 'notes-history',
type: 'PUT',
contentType: 'application/json',
data: JSON.stringify(row),
success: result => console.log('Note history ' + row.note_history_id + ' encrypted'),
error: () => alert("Error encrypting note history.")
success: result => console.log('Note history ' + row.note_history_id + ' de/encrypted'),
error: () => alert("Error de/encrypting note history.")
});
break;
}
},
error: () => alert("Error getting note history.")
@ -276,6 +284,8 @@ function decryptNoteAndSendToServer() {
saveNoteToServer(note);
changeEncryptionOnNoteHistory(note.detail.note_id, false);
setNoteBackgroundIfEncrypted(note);
});
}

View file

@ -21,7 +21,7 @@ router.get('/:noteId', auth.checkApiAuth, async (req, res, next) => {
res.send(history);
});
router.put('/', auth.checkApiAuth, async (req, res, next) => {
router.put('', auth.checkApiAuth, async (req, res, next) => {
await sql.doInTransaction(async () => {
await sql.replace("notes_history", req.body);