From 8f711465194f6779271825bdb2413658880f4c18 Mon Sep 17 00:00:00 2001 From: joel Date: Sun, 26 Dec 2021 17:02:12 +0200 Subject: Fixed bug in day validation & food searching --- server.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'server.js') diff --git a/server.js b/server.js index ca4beea..f2752e4 100644 --- a/server.js +++ b/server.js @@ -87,6 +87,7 @@ function openFile(path) async function buildMain(args) { + // get the passed arguments const path = args["path"]; const query = args["query"]; const foods = args["foods"]; @@ -97,14 +98,18 @@ async function buildMain(args) const data = await openFile(path); let data_string = data.toString("utf-8"); + // here are the things to replace in the html page let res = {}; + // get valid day const d = new Date(); let day = d.getDay(); - const actualDay = day; - day = +((day === 0) || (day === 6)) + (+(!(day === 0) && !(day === 6)) * day); - if ((typeof query.day === "string") && (parseInt(query.day).toString() === query.day) && (!isNaN(parseInt(query.day))) && (parseInt(query.day) > 0) && (parseInt(query.day) < 7)) + let actualDay = day; + day = +((day === 0) || (day === 6)) + (+(!(day === 0) && !(day === 6)) * day); // clamp the day between monday (1) and friday (5) (inclusive) + // make the day the passed day instead if the passed day is valid + if ((typeof query.day === "string") && (parseInt(query.day).toString() === query.day) && (!isNaN(parseInt(query.day))) && (parseInt(query.day) > 0) && (parseInt(query.day) < 6)) day = parseInt(query.day); + // set the day selected (must be done manually with this replacement system) data_string = data_string.replace(`