From 4bd49602feea61cf9716fbfc2cf159246dedebae Mon Sep 17 00:00:00 2001 From: Mathias Wagner Date: Sun, 20 Nov 2022 18:23:23 +0100 Subject: [PATCH] Integrated the new "view access" system into the speedtest route --- server/routes/speedtests.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/server/routes/speedtests.js b/server/routes/speedtests.js index 248da419..dd3c497c 100644 --- a/server/routes/speedtests.js +++ b/server/routes/speedtests.js @@ -3,19 +3,20 @@ const tests = require('../controller/speedtests'); const pauseController = require('../controller/pause'); const config = require('../controller/config'); const testTask = require("../tasks/speedtest"); +const password = require('../middlewares/password'); // List all speedtests -app.get("/", async (req, res) => { +app.get("/", password(true), async (req, res) => { res.json(await tests.list(req.query.hours || 24)); }); // List all speedtests by average -app.get("/averages", async (req, res) => { +app.get("/averages", password(true), async (req, res) => { res.json(await tests.listAverage(req.query.days || 7)); }); // Runs a speedtest -app.post("/run", async (req, res) => { +app.post("/run", password(false), async (req, res) => { if (pauseController.currentState) return res.status(410).json({message: "The speedtests are currently paused"}); if ((await config.get("acceptOoklaLicense")).value === 'false') return res.status(410).json({message: "You need to accept the ookla license first"}); let speedtest = await testTask.create("custom"); @@ -24,12 +25,12 @@ app.post("/run", async (req, res) => { }); // Get the current test status -app.get("/status", (req, res) => { +app.get("/status", password(true), (req, res) => { res.json({paused: pauseController.currentState, running: testTask.isRunning()}); }); // Pauses all speedtests -app.post("/pause", (req, res) => { +app.post("/pause", password(false), (req, res) => { if (!req.body.resumeIn) return res.status(400).json({message: "You need to provide when to resume"}); if (req.body.resumeIn === -1) { @@ -42,20 +43,20 @@ app.post("/pause", (req, res) => { }); // Ends the pause-state -app.post("/continue", (req, res) => { +app.post("/continue", password(false), (req, res) => { pauseController.updateState(false); res.json({message: "Successfully resumed the speedtests"}); }); // Get a specific speedtest -app.get("/:id", async (req, res) => { +app.get("/:id", password(true), async (req, res) => { let test = await tests.get(req.params.id); if (test === null) return res.status(404).json({message: "Speedtest not found"}); res.json(test); }); // Delete a specific speedtest -app.delete("/:id", async (req, res) => { +app.delete("/:id", password(false), async (req, res) => { let test = await tests.delete(req.params.id); if (!test) return res.status(404).json({message: "Speedtest not found"}); res.json({message: "Successfully deleted the provided speedtest"});