mirror of
https://github.com/zadam/trilium.git
synced 2025-10-19 22:58:52 +02:00
refactor(server): fix a few cyclic dependencies regarding protected_session
This commit is contained in:
parent
b2fcf5fa6c
commit
a8011e4755
@ -1,9 +1,6 @@
|
||||
"use strict";
|
||||
|
||||
import log from "./log.js";
|
||||
import dataEncryptionService from "./encryption/data_encryption.js";
|
||||
import options from "./options.js";
|
||||
import ws from "./ws.js";
|
||||
|
||||
let dataKey: Buffer | null = null;
|
||||
|
||||
@ -15,11 +12,11 @@ function getDataKey() {
|
||||
return dataKey;
|
||||
}
|
||||
|
||||
function resetDataKey() {
|
||||
export function resetDataKey() {
|
||||
dataKey = null;
|
||||
}
|
||||
|
||||
function isProtectedSessionAvailable() {
|
||||
export function isProtectedSessionAvailable() {
|
||||
return !!dataKey;
|
||||
}
|
||||
|
||||
@ -57,15 +54,8 @@ function touchProtectedSession() {
|
||||
}
|
||||
}
|
||||
|
||||
function checkProtectedSessionExpiration() {
|
||||
const protectedSessionTimeout = options.getOptionInt("protectedSessionTimeout");
|
||||
if (isProtectedSessionAvailable() && lastProtectedSessionOperationDate && Date.now() - lastProtectedSessionOperationDate > protectedSessionTimeout * 1000) {
|
||||
resetDataKey();
|
||||
|
||||
log.info("Expiring protected session");
|
||||
|
||||
ws.reloadFrontend("leaving protected session");
|
||||
}
|
||||
export function getLastProtectedSessionOperationDate() {
|
||||
return lastProtectedSessionOperationDate;
|
||||
}
|
||||
|
||||
export default {
|
||||
@ -75,6 +65,5 @@ export default {
|
||||
encrypt,
|
||||
decrypt,
|
||||
decryptString,
|
||||
touchProtectedSession,
|
||||
checkProtectedSessionExpiration
|
||||
touchProtectedSession
|
||||
};
|
||||
|
@ -4,9 +4,11 @@ import sqlInit from "./sql_init.js";
|
||||
import config from "./config.js";
|
||||
import log from "./log.js";
|
||||
import attributeService from "../services/attributes.js";
|
||||
import protectedSessionService from "../services/protected_session.js";
|
||||
import hiddenSubtreeService from "./hidden_subtree.js";
|
||||
import type BNote from "../becca/entities/bnote.js";
|
||||
import options from "./options.js";
|
||||
import { getLastProtectedSessionOperationDate, isProtectedSessionAvailable, resetDataKey } from "./protected_session.js";
|
||||
import ws from "./ws.js";
|
||||
|
||||
function getRunAtHours(note: BNote): number[] {
|
||||
try {
|
||||
@ -64,5 +66,15 @@ sqlInit.dbReady.then(() => {
|
||||
);
|
||||
}
|
||||
|
||||
setInterval(() => protectedSessionService.checkProtectedSessionExpiration(), 30000);
|
||||
setInterval(() => checkProtectedSessionExpiration(), 1);
|
||||
});
|
||||
|
||||
function checkProtectedSessionExpiration() {
|
||||
const protectedSessionTimeout = options.getOptionInt("protectedSessionTimeout");
|
||||
const lastProtectedSessionOperationDate = getLastProtectedSessionOperationDate();
|
||||
if (isProtectedSessionAvailable() && lastProtectedSessionOperationDate && Date.now() - lastProtectedSessionOperationDate > protectedSessionTimeout * 1000) {
|
||||
resetDataKey();
|
||||
log.info("Expiring protected session");
|
||||
ws.reloadFrontend("leaving protected session");
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user