');
// get the food
const week = +(day < actualDay) + 1; // Week = 1 if day is not past
const [food, vege] = await Promise.all([
SQLDB.execute(
"SELECT header, datestring, food FROM foods WHERE week=? AND day=? AND vegetarian=FALSE",
[week, day]
),
SQLDB.execute(
"SELECT header, datestring, food FROM foods WHERE week=? AND day=? AND vegetarian=TRUE",
[week, day]
)
]);
if (food[0] !== undefined) {
res["food-header"] = `${food[0].header} ${food[0].datestring}`;
res["food"] = food[0].food;
} else {
res["food-header"] = `Kouluruoka ${weekdays[day]}`;
res["food"] = "Päivän ruoka puuttuu tietokannasta.";
}
if ((vege[0] !== undefined) && (vege[0].food !== res["food"])) {
res["vege-header"] = vege[0].header;
res["vege"] = vege[0].food;
} else {
res["vege-header"] = "";
res["vege"] = "";
}
data_string = build_replace(data_string, res);
return data_string;
}
async function buildDevs(args)
{
const path = args["path"];
const data = await open.file(path);
const DB = args["sqldb"];
let res = "";
let devs = await DB.query_raw("SELECT name, description, contact FROM devs");
for (let dev = 0; dev < devs.length; dev++)
{
let devInfo = devs[dev];
res += '
';
}
return build_replace(data.toString("utf-8"), {"devs": res});
}
async function buildCustomMessage(header, message) {
let data = await open.file("./Cont/custom-message/index.html");
data = data
.toString("utf-8")
.replace("\\(header\\)", header)
.replace("\\(content\\)", message);
return data;
}
async function buildPanel(args)
{
let data = await open.file(args["path"]);
data = data.toString("utf-8");
let shifts = await open.file(SHIFTPATH);
shifts = shifts.toString("utf-8");
let classes = await open.file(CLASSPATH);
classes = classes.toString("utf-8");
let exceptions = await open.file(EXCEPTIONPATH);
exceptions = exceptions.toString("utf-8");
return build_replace(data, {
"shifts": shifts,
"classes": classes,
"exceptions": exceptions
});
}
async function build404(args)
{
args["path"] = args["path"].substring("./Cont".length);
const data = await open.file(args["path404"]);
const data_string = data.toString("utf-8");
return data_string.replace("\\(path\\)", args["path"]);
}
async function buildDefault(args)
{
const path = args["path"];
const data = await open.file(path);
return data.toString("utf-8");
}
async function buildImage(args)
{
const path = args["path"];
const data = await open.file(path);
return data;
}
function build_replace(s, dict)
{
for (const [key, val] of Object.entries(dict))
{
s = s.replaceAll(`\\(${key}\\)`, val);
}
return s;
}
init();