trilium/services/request_context.js

31 lines
712 B
JavaScript
Raw Normal View History

"use strict";
const protected_session = require('./protected_session');
module.exports = function(req) {
function isProtectedSessionAvailable() {
return protected_session.isProtectedSessionAvailable(req);
}
function getDataKey() {
if (!isProtectedSessionAvailable()) {
2017-12-07 09:58:59 +08:00
throw new Error("Protected session is not available");
}
return protected_session.getDataKey(req);
}
function getDataKeyOrNull() {
if (!isProtectedSessionAvailable()) {
return null;
}
return protected_session.getDataKey(req);
}
return {
isProtectedSessionAvailable,
getDataKey,
getDataKeyOrNull
};
};