mirror of
https://github.com/zadam/trilium.git
synced 2025-10-21 07:38:53 +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";
|
"use strict";
|
||||||
|
|
||||||
import log from "./log.js";
|
|
||||||
import dataEncryptionService from "./encryption/data_encryption.js";
|
import dataEncryptionService from "./encryption/data_encryption.js";
|
||||||
import options from "./options.js";
|
|
||||||
import ws from "./ws.js";
|
|
||||||
|
|
||||||
let dataKey: Buffer | null = null;
|
let dataKey: Buffer | null = null;
|
||||||
|
|
||||||
@ -15,11 +12,11 @@ function getDataKey() {
|
|||||||
return dataKey;
|
return dataKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
function resetDataKey() {
|
export function resetDataKey() {
|
||||||
dataKey = null;
|
dataKey = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isProtectedSessionAvailable() {
|
export function isProtectedSessionAvailable() {
|
||||||
return !!dataKey;
|
return !!dataKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,15 +54,8 @@ function touchProtectedSession() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkProtectedSessionExpiration() {
|
export function getLastProtectedSessionOperationDate() {
|
||||||
const protectedSessionTimeout = options.getOptionInt("protectedSessionTimeout");
|
return lastProtectedSessionOperationDate;
|
||||||
if (isProtectedSessionAvailable() && lastProtectedSessionOperationDate && Date.now() - lastProtectedSessionOperationDate > protectedSessionTimeout * 1000) {
|
|
||||||
resetDataKey();
|
|
||||||
|
|
||||||
log.info("Expiring protected session");
|
|
||||||
|
|
||||||
ws.reloadFrontend("leaving protected session");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@ -75,6 +65,5 @@ export default {
|
|||||||
encrypt,
|
encrypt,
|
||||||
decrypt,
|
decrypt,
|
||||||
decryptString,
|
decryptString,
|
||||||
touchProtectedSession,
|
touchProtectedSession
|
||||||
checkProtectedSessionExpiration
|
|
||||||
};
|
};
|
||||||
|
@ -4,9 +4,11 @@ import sqlInit from "./sql_init.js";
|
|||||||
import config from "./config.js";
|
import config from "./config.js";
|
||||||
import log from "./log.js";
|
import log from "./log.js";
|
||||||
import attributeService from "../services/attributes.js";
|
import attributeService from "../services/attributes.js";
|
||||||
import protectedSessionService from "../services/protected_session.js";
|
|
||||||
import hiddenSubtreeService from "./hidden_subtree.js";
|
import hiddenSubtreeService from "./hidden_subtree.js";
|
||||||
import type BNote from "../becca/entities/bnote.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[] {
|
function getRunAtHours(note: BNote): number[] {
|
||||||
try {
|
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