Updated the speedtests.js controller

This commit is contained in:
Mathias Wagner
2024-05-21 00:52:00 +02:00
parent 887a28019d
commit bb1c026e79
2 changed files with 10 additions and 2 deletions
+8
View File
@@ -13,6 +13,14 @@ module.exports.getOne = async (id) => {
return speedtest
}
module.exports.listAll = async () => {
let dbEntries = await tests.findAll({order: [["created", "DESC"]]});
for (let dbEntry of dbEntries)
if (dbEntry.error === null) delete dbEntry.error;
return dbEntries;
}
module.exports.listTests = async (hours = 24, start, limit) => {
limit = parseInt(limit) || 10;
const whereClause = start ? {id: {[Op.lt]: start}} : undefined;
+2 -2
View File
@@ -9,12 +9,12 @@ app.get("/", password(false), async (req, res) => {
app.get("/tests/history/json", password(false), async (req, res) => {
res.set({"Content-Disposition": "attachment; filename=\"speedtests.json\""});
res.send(JSON.stringify(await tests.listTests(), null, 4));
res.send(JSON.stringify(await tests.listAll(), null, 4));
});
app.get("/tests/history/csv", password(false), async (req, res) => {
res.set({"Content-Disposition": "attachment; filename=\"speedtests.csv\""});
let list = await tests.listTests();
let list = await tests.listAll();
if (list.length === 0) return res.send("");
let fields = Object.keys(list[0]);