Implemented a config check for the 'acceptOoklaLicense' config value & fixed a bug in the config route

This commit is contained in:
Mathias Wagner
2022-10-16 14:29:47 +02:00
parent d0d5d1ebc0
commit da428e79fd
+5 -2
View File
@@ -23,11 +23,14 @@ app.get("/:key", async (req, res) => {
// Updates a specific config entry
app.patch("/:key", async (req, res) => {
if (!req.body.value) return res.status(400).json({message: "You need to provide the new value"});
if (!req.body.value.toString()) return res.status(400).json({message: "You need to provide the new value"});
if ((req.params.key === "ping" || req.params.key === "download" || req.params.key === "upload") && isNaN(req.body.value))
return res.status(400).json({message: "You need to provide a number in order to change this"});
if (req.params.key === "acceptOoklaLicense" && typeof req.body.value !== "boolean")
return res.status(400).json({message: "You need to provide a boolean value"});
if (req.params.key === "ping")
req.body.value = req.body.value.toString().split(".")[0];
@@ -36,7 +39,7 @@ app.patch("/:key", async (req, res) => {
if (req.params.key === "cron" && !cron.isValidCron(req.body.value.toString()))
return res.status(500).json({message: "Not a valid cron expression"});
if (!await config.update(req.params.key, req.body.value)) return res.status(404).json({message: "The provided key does not exist"});
if (!await config.update(req.params.key, req.body.value.toString())) return res.status(404).json({message: "The provided key does not exist"});
if (req.params.key === "cron") {
timer.stopTimer();