[mod] session management:Datenbank anbinden
This commit is contained in:
parent
208aa12fd9
commit
46ee340e17
2 changed files with 153 additions and 136 deletions
|
@ -83,8 +83,9 @@ namespace _espe.conf
|
|||
}
|
||||
);
|
||||
session_management : {
|
||||
lifetime : int;
|
||||
in_memory : boolean;
|
||||
drop_all_at_start : boolean;
|
||||
lifetime : int;
|
||||
};
|
||||
settings : {
|
||||
target_domain : string;
|
||||
|
@ -114,14 +115,26 @@ namespace _espe.conf
|
|||
* @todo mandatory fields
|
||||
*/
|
||||
export async function load(
|
||||
path : (null | string)
|
||||
path : string
|
||||
) : Promise<void>
|
||||
{
|
||||
const conf_raw : any = (
|
||||
(path !== null)
|
||||
? (lib_plankton.json.decode(await lib_plankton.file.read(path)) as type_conf)
|
||||
: {}
|
||||
);
|
||||
let conf_raw : any;
|
||||
if (! (await lib_plankton.file.exists(path))) {
|
||||
// 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 = {
|
||||
"general": (
|
||||
((node_general) => ({
|
||||
|
@ -213,8 +226,9 @@ namespace _espe.conf
|
|||
),
|
||||
"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),
|
||||
"lifetime": (node_session_management["lifetime"] ?? 900),
|
||||
})) (conf_raw["session_management"] ?? {})
|
||||
),
|
||||
"settings": (
|
||||
|
@ -232,6 +246,7 @@ namespace _espe.conf
|
|||
// process.stderr.write(JSON.stringify(_data, undefined, "\t"));
|
||||
return Promise.resolve<void>(undefined);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
@ -79,7 +79,7 @@ async function main(
|
|||
"indicators_short": ["c"],
|
||||
"type": lib_plankton.args.enum_type.string,
|
||||
"mode": lib_plankton.args.enum_mode.replace,
|
||||
"default": null,
|
||||
"default": "conf.json",
|
||||
"info": "Pfad zur Konfigurations-Datei",
|
||||
"name": "conf-path",
|
||||
}),
|
||||
|
@ -175,12 +175,14 @@ async function main(
|
|||
|
||||
await lib_plankton.session.setup(
|
||||
{
|
||||
/*
|
||||
"data_chest": lib_plankton.call.convey(
|
||||
"data_chest": (
|
||||
_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(
|
||||
{
|
||||
"database_implementation": _espe.helpers.database_implementation(),
|
||||
"table_name": "session_management",
|
||||
"table_name": "sessions",
|
||||
"key_names": ["key"],
|
||||
}
|
||||
),
|
||||
|
@ -188,15 +190,15 @@ async function main(
|
|||
(core) => ({
|
||||
"setup": (input) => core.setup(undefined),
|
||||
"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]),
|
||||
"read": (key) => core.read([key]),
|
||||
"read": (key) => core.read([key]).then(row => JSON.parse(row["data"])),
|
||||
// "search": (term) => core.search(term).then(() => []),
|
||||
"search": (term) => Promise.reject(new Error("not implemented")),
|
||||
}),
|
||||
]
|
||||
)
|
||||
),
|
||||
*/
|
||||
"default_lifetime": _espe.conf.get().session_management.lifetime,
|
||||
}
|
||||
);
|
||||
|
|
Loading…
Add table
Reference in a new issue