mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
fixed unloading the encrypted page after encryption timeout by simply reloading the app completely plus some unrelated refactorings
This commit is contained in:
parent
9c88fc6060
commit
b192336113
@ -26,7 +26,7 @@ const settings = (function() {
|
|||||||
|
|
||||||
tabsEl.tabs();
|
tabsEl.tabs();
|
||||||
|
|
||||||
for (module of settingModules) {
|
for (const module of settingModules) {
|
||||||
module.settingsLoaded(settings);
|
module.settingsLoaded(settings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,10 +22,6 @@ const encryption = (function() {
|
|||||||
encryptedDataKey = settings.encrypted_data_key;
|
encryptedDataKey = settings.encrypted_data_key;
|
||||||
});
|
});
|
||||||
|
|
||||||
function setEncryptionSalt(encSalt) {
|
|
||||||
encryptionSalt = encSalt;
|
|
||||||
}
|
|
||||||
|
|
||||||
function setEncryptedDataKey(encDataKey) {
|
function setEncryptedDataKey(encDataKey) {
|
||||||
encryptedDataKey = encDataKey;
|
encryptedDataKey = encDataKey;
|
||||||
}
|
}
|
||||||
@ -149,15 +145,9 @@ const encryption = (function() {
|
|||||||
dataKey = null;
|
dataKey = null;
|
||||||
|
|
||||||
if (noteEditor.getCurrentNote().detail.encryption > 0) {
|
if (noteEditor.getCurrentNote().detail.encryption > 0) {
|
||||||
noteEditor.loadNoteToEditor(noteEditor.getCurrentNoteId());
|
// most secure solution - guarantees nothing remained in memory
|
||||||
|
// since this expires because user doesn't use the app, it shouldn't be disruptive
|
||||||
for (const noteId of glob.allNoteIds) {
|
window.location.reload(true);
|
||||||
const note = getNodeByKey(noteId);
|
|
||||||
|
|
||||||
if (note.data.encryption > 0) {
|
|
||||||
note.setTitle("[encrypted]");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,7 +11,6 @@ const noteEditor = (function() {
|
|||||||
const encryptionPasswordEl = $("#encryption-password");
|
const encryptionPasswordEl = $("#encryption-password");
|
||||||
|
|
||||||
let currentNote = null;
|
let currentNote = null;
|
||||||
let currentNoteLoadTime = null;
|
|
||||||
|
|
||||||
let noteChangeDisabled = false;
|
let noteChangeDisabled = false;
|
||||||
|
|
||||||
@ -26,7 +25,7 @@ const noteEditor = (function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getCurrentNoteLoadTime() {
|
function getCurrentNoteLoadTime() {
|
||||||
return currentNoteLoadTime;
|
return currentNote ? currentNote.loadTime : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function noteChanged() {
|
function noteChanged() {
|
||||||
@ -100,9 +99,6 @@ const noteEditor = (function() {
|
|||||||
message("Saved!");
|
message("Saved!");
|
||||||
}
|
}
|
||||||
|
|
||||||
currentNote = null;
|
|
||||||
currentNoteLoadTime = null;
|
|
||||||
|
|
||||||
function createNewTopLevelNote() {
|
function createNewTopLevelNote() {
|
||||||
let rootNode = treeEl.fancytree("getRootNode");
|
let rootNode = treeEl.fancytree("getRootNode");
|
||||||
|
|
||||||
@ -179,9 +175,7 @@ const noteEditor = (function() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function loadNoteToEditor(noteId) {
|
async function loadNoteToEditor(noteId) {
|
||||||
const note = await $.get(baseApiUrl + 'notes/' + noteId);
|
currentNote = await $.get(baseApiUrl + 'notes/' + noteId);
|
||||||
currentNote = note;
|
|
||||||
currentNoteLoadTime = Math.floor(new Date().getTime() / 1000);
|
|
||||||
|
|
||||||
if (newNoteCreated) {
|
if (newNoteCreated) {
|
||||||
newNoteCreated = false;
|
newNoteCreated = false;
|
||||||
@ -189,7 +183,7 @@ const noteEditor = (function() {
|
|||||||
noteTitleEl.focus().select();
|
noteTitleEl.focus().select();
|
||||||
}
|
}
|
||||||
|
|
||||||
await encryption.ensureEncryptionIsAvailable(note.detail.encryption > 0, false);
|
await encryption.ensureEncryptionIsAvailable(currentNote.detail.encryption > 0, false);
|
||||||
|
|
||||||
noteDetailWrapperEl.show();
|
noteDetailWrapperEl.show();
|
||||||
|
|
||||||
@ -201,24 +195,24 @@ const noteEditor = (function() {
|
|||||||
|
|
||||||
encryptionPasswordEl.val('');
|
encryptionPasswordEl.val('');
|
||||||
|
|
||||||
encryption.decryptNoteIfNecessary(note);
|
encryption.decryptNoteIfNecessary(currentNote);
|
||||||
|
|
||||||
noteTitleEl.val(note.detail.note_title);
|
noteTitleEl.val(currentNote.detail.note_title);
|
||||||
|
|
||||||
noteChangeDisabled = true;
|
noteChangeDisabled = true;
|
||||||
|
|
||||||
// Clear contents and remove all stored history. This is to prevent undo from going across notes
|
// Clear contents and remove all stored history. This is to prevent undo from going across notes
|
||||||
noteDetailEl.summernote('reset');
|
noteDetailEl.summernote('reset');
|
||||||
|
|
||||||
noteDetailEl.summernote('code', note.detail.note_text);
|
noteDetailEl.summernote('code', currentNote.detail.note_text);
|
||||||
|
|
||||||
document.location.hash = noteId;
|
document.location.hash = noteId;
|
||||||
|
|
||||||
recentNotes.addRecentNote(noteId, note.detail.note_id);
|
recentNotes.addRecentNote(noteId, currentNote.detail.note_id);
|
||||||
|
|
||||||
noteChangeDisabled = false;
|
noteChangeDisabled = false;
|
||||||
|
|
||||||
setNoteBackgroundIfEncrypted(note);
|
setNoteBackgroundIfEncrypted(currentNote);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadNote(noteId) {
|
async function loadNote(noteId) {
|
||||||
|
@ -12,7 +12,7 @@ const status = (function() {
|
|||||||
data: JSON.stringify({
|
data: JSON.stringify({
|
||||||
treeLoadTime: noteTree.getTreeLoadTime(),
|
treeLoadTime: noteTree.getTreeLoadTime(),
|
||||||
currentNoteId: noteEditor.getCurrentNoteId(),
|
currentNoteId: noteEditor.getCurrentNoteId(),
|
||||||
currentNoteDateModified: noteEditor.getCurrentNoteLoadTime()
|
currentNoteLoadTime: noteEditor.getCurrentNoteLoadTime()
|
||||||
}),
|
}),
|
||||||
statusCode: {
|
statusCode: {
|
||||||
401: () => {
|
401: () => {
|
||||||
|
@ -21,8 +21,9 @@ router.get('/:noteId', auth.checkApiAuth, async (req, res, next) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
res.send({
|
res.send({
|
||||||
'detail': detail,
|
detail: detail,
|
||||||
'images': await sql.getResults("select * from images where note_id = ? order by note_offset", [noteId])
|
images: await sql.getResults("select * from images where note_id = ? order by note_offset", [noteId]),
|
||||||
|
loadTime: utils.nowTimestamp()
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@ const audit_category = require('../../services/audit_category');
|
|||||||
router.post('', auth.checkApiAuth, async (req, res, next) => {
|
router.post('', auth.checkApiAuth, async (req, res, next) => {
|
||||||
const treeLoadTime = req.body.treeLoadTime;
|
const treeLoadTime = req.body.treeLoadTime;
|
||||||
const currentNoteId = req.body.currentNoteId;
|
const currentNoteId = req.body.currentNoteId;
|
||||||
const currentNoteDateModified = req.body.currentNoteDateModified;
|
const currentNoteLoadTime = req.body.currentNoteLoadTime;
|
||||||
|
|
||||||
const browserId = req.get('x-browser-id');
|
const browserId = req.get('x-browser-id');
|
||||||
|
|
||||||
@ -20,13 +20,13 @@ router.post('', auth.checkApiAuth, async (req, res, next) => {
|
|||||||
audit_category.UPDATE_TITLE, audit_category.CHANGE_PARENT, audit_category.CHANGE_POSITION]);
|
audit_category.UPDATE_TITLE, audit_category.CHANGE_PARENT, audit_category.CHANGE_POSITION]);
|
||||||
|
|
||||||
const currentNoteChangesCount = await sql.getSingleValue("SELECT COUNT(*) FROM audit_log WHERE (browser_id IS NULL OR browser_id != ?) " +
|
const currentNoteChangesCount = await sql.getSingleValue("SELECT COUNT(*) FROM audit_log WHERE (browser_id IS NULL OR browser_id != ?) " +
|
||||||
"AND date_modified >= ? AND note_id = ? AND category IN (?)", [browserId, currentNoteDateModified, currentNoteId,
|
"AND date_modified >= ? AND note_id = ? AND category IN (?)", [browserId, currentNoteLoadTime, currentNoteId,
|
||||||
audit_category.UPDATE_CONTENT]);
|
audit_category.UPDATE_CONTENT]);
|
||||||
|
|
||||||
if (currentNoteChangesCount > 0) {
|
if (currentNoteChangesCount > 0) {
|
||||||
console.log("Current note changed!");
|
console.log("Current note changed!");
|
||||||
console.log("SELECT COUNT(*) FROM audit_log WHERE (browser_id IS NULL OR browser_id != '" + browserId + "') " +
|
console.log("SELECT COUNT(*) FROM audit_log WHERE (browser_id IS NULL OR browser_id != '" + browserId + "') " +
|
||||||
"AND date_modified >= " + currentNoteDateModified + " AND note_id = '" + currentNoteId + "' AND category IN ('" + audit_category.UPDATE_CONTENT + "')");
|
"AND date_modified >= " + currentNoteLoadTime + " AND note_id = '" + currentNoteId + "' AND category IN ('" + audit_category.UPDATE_CONTENT + "')");
|
||||||
}
|
}
|
||||||
|
|
||||||
let changesToPushCount = 0;
|
let changesToPushCount = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user