2024-05-20 22:04:23 +02:00
|
|
|
/*
|
|
|
|
Espe | Ein schlichtes Werkzeug zur Mitglieder-Verwaltung | Frontend
|
|
|
|
Copyright (C) 2024 Christian Fraß
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
|
|
|
|
License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
|
|
|
|
version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
|
|
|
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along with this program. If not, see
|
|
|
|
<https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2024-04-22 10:24:38 +02:00
|
|
|
namespace _espe.conf
|
2024-04-22 10:02:43 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
*/
|
|
|
|
export type type_data = {
|
|
|
|
backend : {
|
|
|
|
scheme : string;
|
|
|
|
host : string;
|
|
|
|
port : int;
|
|
|
|
path_base : string;
|
|
|
|
};
|
2024-04-24 08:33:22 +02:00
|
|
|
settings : {
|
|
|
|
title : string;
|
2024-05-01 09:53:59 +02:00
|
|
|
test_mode : boolean;
|
2024-04-24 08:33:22 +02:00
|
|
|
};
|
2024-04-22 10:02:43 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
*/
|
|
|
|
var _data : (null | type_data) = null;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
*/
|
|
|
|
export async function load(
|
|
|
|
) : Promise<void>
|
|
|
|
{
|
2024-04-25 23:30:16 +02:00
|
|
|
let data_raw;
|
|
|
|
try {
|
|
|
|
data_raw = lib_plankton.json.decode(await lib_plankton.file.read("conf.json"));
|
|
|
|
}
|
|
|
|
catch (error) {
|
|
|
|
data_raw = {};
|
|
|
|
console.warn("could not read configuration file");
|
|
|
|
}
|
|
|
|
_data = {
|
|
|
|
"backend": (
|
|
|
|
(node_backend => ({
|
|
|
|
"scheme": (node_backend["scheme"] ?? "http"),
|
|
|
|
"host": (node_backend["host"] ?? "localhost"),
|
|
|
|
"port": (node_backend["port"] ?? 7979),
|
|
|
|
"path_base": (node_backend["path_base"] ?? ""),
|
|
|
|
})) (data_raw["backend"] ?? {})
|
|
|
|
),
|
|
|
|
"settings": (
|
|
|
|
(node_settings => ({
|
|
|
|
"title": (node_settings["title"] ?? "Espe"),
|
2024-05-01 09:53:59 +02:00
|
|
|
"test_mode": (node_settings["test_mode"] ?? false),
|
2024-04-25 23:30:16 +02:00
|
|
|
})) (data_raw["settings"] ?? {})
|
|
|
|
),
|
|
|
|
};
|
2024-04-22 10:02:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
*/
|
|
|
|
export function get(
|
|
|
|
) : type_data
|
|
|
|
{
|
|
|
|
if (_data === null) {
|
|
|
|
throw (new Error("conf not loaded yet"));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return _data;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|