Skip to content

Commit

Permalink
moved protected session expiration scheduling #2855
Browse files Browse the repository at this point in the history
  • Loading branch information
zadam committed May 17, 2022
1 parent c24c807 commit 37eb16b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/services/protected_session.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
const log = require('./log');
const dataEncryptionService = require('./data_encryption');
const options = require("./options");
const sqlInit = require("./sql_init");

let dataKey = null;

Expand Down Expand Up @@ -64,20 +63,19 @@ function touchProtectedSession() {
}
}

sqlInit.dbReady.then(() => {
setInterval(() => {
const protectedSessionTimeout = options.getOptionInt('protectedSessionTimeout');
if (isProtectedSessionAvailable()
&& lastProtectedSessionOperationDate
&& Date.now() - lastProtectedSessionOperationDate > protectedSessionTimeout * 1000) {
function checkProtectedSessionExpiration() {
const protectedSessionTimeout = options.getOptionInt('protectedSessionTimeout');
if (isProtectedSessionAvailable()
&& lastProtectedSessionOperationDate
&& Date.now() - lastProtectedSessionOperationDate > protectedSessionTimeout * 1000) {

resetDataKey();
resetDataKey();

require('./ws').reloadFrontend();
}
}, 30000);
});
log.info("Expiring protected session");

require('./ws').reloadFrontend();
}
}

module.exports = {
setDataKey,
Expand All @@ -87,5 +85,6 @@ module.exports = {
decrypt,
decryptString,
decryptNotes,
touchProtectedSession
touchProtectedSession,
checkProtectedSessionExpiration
};
3 changes: 3 additions & 0 deletions src/services/scheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const log = require('./log');
const sql = require("./sql");
const becca = require("../becca/becca");
const specialNotesService = require("../services/special_notes");
const protectedSessionService = require("../services/protected_session");

function getRunAtHours(note) {
try {
Expand Down Expand Up @@ -59,4 +60,6 @@ sqlInit.dbReady.then(() => {

setTimeout(cls.wrap(() => specialNotesService.createMissingSpecialNotes()), 10 * 1000);
}

setInterval(() => protectedSessionService.checkProtectedSessionExpiration(), 30000);
});

0 comments on commit 37eb16b

Please sign in to comment.