38 lines
808 B
JavaScript
38 lines
808 B
JavaScript
import sql from "./sql";
|
|
|
|
let cfg = {
|
|
client: {},
|
|
main: {},
|
|
websrv: {},
|
|
trigger: {}
|
|
};
|
|
|
|
const read = () => new Promise((resolve, reject) => {
|
|
sql.exec("select * from cfg").then(rows => {
|
|
for (let row in rows) {
|
|
cfg[rows[row].class][rows[row].key] = {
|
|
val: ((type, value) => {
|
|
switch (type) {
|
|
case "string":
|
|
return value;
|
|
case "int":
|
|
return parseInt(value);
|
|
case "bool":
|
|
return value === "true";
|
|
case "json":
|
|
return JSON.parse(value);
|
|
}
|
|
})(rows[row].type, rows[row].value),
|
|
hidden: rows[row].hidden === 1,
|
|
type: rows[row].type
|
|
}
|
|
}
|
|
resolve();
|
|
})
|
|
.catch(err => {
|
|
reject("no cfg");
|
|
})
|
|
});
|
|
|
|
export { cfg, read };
|