note history decryption now works, more cleanup

This commit is contained in:
azivner
2017-11-14 22:21:56 -05:00
parent ff411f00b1
commit 0a0421ec7e
10 changed files with 63 additions and 1083 deletions

View File

@@ -4,18 +4,20 @@ const express = require('express');
const router = express.Router();
const sql = require('../../services/sql');
const auth = require('../../services/auth');
const data_encryption = require('../../services/data_encryption');
const protected_session = require('../../services/protected_session');
router.get('/:noteId', auth.checkApiAuth, async (req, res, next) => {
const noteId = req.params.noteId;
const isProtected = req.query.is_protected;
const history = await sql.getResults("select * from notes_history where note_id = ? order by date_modified_to desc", [noteId]);
let history;
const dataKey = protected_session.getDataKey(req);
if (isProtected === undefined) {
history = await sql.getResults("select * from notes_history where note_id = ? order by date_modified_to desc", [noteId]);
}
else {
history = await sql.getResults("select * from notes_history where note_id = ? and is_protected = ? order by date_modified_to desc", [noteId, is_protected]);
for (const hist of history) {
if (hist.is_protected) {
hist.note_title = data_encryption.decrypt(dataKey, hist.note_title);
hist.note_text = data_encryption.decrypt(dataKey, hist.note_text);
}
}
res.send(history);