[mod] session management:Datenbank anbinden

This commit is contained in:
roydfalk 2024-04-26 11:02:52 +02:00
parent 208aa12fd9
commit 46ee340e17
2 changed files with 153 additions and 136 deletions

View file

@ -83,8 +83,9 @@ namespace _espe.conf
} }
); );
session_management : { session_management : {
lifetime : int; in_memory : boolean;
drop_all_at_start : boolean; drop_all_at_start : boolean;
lifetime : int;
}; };
settings : { settings : {
target_domain : string; target_domain : string;
@ -114,14 +115,26 @@ namespace _espe.conf
* @todo mandatory fields * @todo mandatory fields
*/ */
export async function load( export async function load(
path : (null | string) path : string
) : Promise<void> ) : Promise<void>
{ {
const conf_raw : any = ( let conf_raw : any;
(path !== null) if (! (await lib_plankton.file.exists(path))) {
? (lib_plankton.json.decode(await lib_plankton.file.read(path)) as type_conf) // return Promise.reject<void>(new Error("configuration file not found: " + path + "; using fallback"));
: {} conf_raw = {};
); }
else {
try {
conf_raw = lib_plankton.json.decode(await lib_plankton.file.read(path));
}
catch (error) {
conf_raw = null;
}
}
if (conf_raw === null) {
return Promise.reject<void>("configuration file could not be read");
}
else {
_data = { _data = {
"general": ( "general": (
((node_general) => ({ ((node_general) => ({
@ -213,8 +226,9 @@ namespace _espe.conf
), ),
"session_management": ( "session_management": (
((node_session_management) => ({ ((node_session_management) => ({
"lifetime": (node_session_management["lifetime"] ?? 900), "in_memory": (node_session_management["in_memory"] ?? true),
"drop_all_at_start": (node_session_management["drop_all_at_start"] ?? true), "drop_all_at_start": (node_session_management["drop_all_at_start"] ?? true),
"lifetime": (node_session_management["lifetime"] ?? 900),
})) (conf_raw["session_management"] ?? {}) })) (conf_raw["session_management"] ?? {})
), ),
"settings": ( "settings": (
@ -232,6 +246,7 @@ namespace _espe.conf
// process.stderr.write(JSON.stringify(_data, undefined, "\t")); // process.stderr.write(JSON.stringify(_data, undefined, "\t"));
return Promise.resolve<void>(undefined); return Promise.resolve<void>(undefined);
} }
}
/** /**

View file

@ -79,7 +79,7 @@ async function main(
"indicators_short": ["c"], "indicators_short": ["c"],
"type": lib_plankton.args.enum_type.string, "type": lib_plankton.args.enum_type.string,
"mode": lib_plankton.args.enum_mode.replace, "mode": lib_plankton.args.enum_mode.replace,
"default": null, "default": "conf.json",
"info": "Pfad zur Konfigurations-Datei", "info": "Pfad zur Konfigurations-Datei",
"name": "conf-path", "name": "conf-path",
}), }),
@ -175,12 +175,14 @@ async function main(
await lib_plankton.session.setup( await lib_plankton.session.setup(
{ {
/* "data_chest": (
"data_chest": lib_plankton.call.convey( _espe.conf.get().session_management.in_memory
? lib_plankton.storage.memory.implementation_chest<lib_plankton.session.type_session>({})
: lib_plankton.call.convey(
lib_plankton.storage.sql_table_common.chest( lib_plankton.storage.sql_table_common.chest(
{ {
"database_implementation": _espe.helpers.database_implementation(), "database_implementation": _espe.helpers.database_implementation(),
"table_name": "session_management", "table_name": "sessions",
"key_names": ["key"], "key_names": ["key"],
} }
), ),
@ -188,15 +190,15 @@ async function main(
(core) => ({ (core) => ({
"setup": (input) => core.setup(undefined), "setup": (input) => core.setup(undefined),
"clear": () => core.clear(), "clear": () => core.clear(),
"write": (key, value) => core.write([key], value), "write": (key, value) => core.write([key], {"data": JSON.stringify(value)}),
"delete": (key) => core.delete([key]), "delete": (key) => core.delete([key]),
"read": (key) => core.read([key]), "read": (key) => core.read([key]).then(row => JSON.parse(row["data"])),
// "search": (term) => core.search(term).then(() => []), // "search": (term) => core.search(term).then(() => []),
"search": (term) => Promise.reject(new Error("not implemented")), "search": (term) => Promise.reject(new Error("not implemented")),
}), }),
] ]
)
), ),
*/
"default_lifetime": _espe.conf.get().session_management.lifetime, "default_lifetime": _espe.conf.get().session_management.lifetime,
} }
); );