mirror of
https://github.com/zadam/trilium.git
synced 2025-12-22 16:20:08 +01:00
note history decryption now works, more cleanup
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user