Skip to content

Commit 4bdc961

Browse files
committed
Bug fixes
1 parent 15475d6 commit 4bdc961

File tree

8 files changed

+18
-8
lines changed

8 files changed

+18
-8
lines changed

client/src/common/components/StorageDialog/tabs/Configuration.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export default () => {
3838
close();
3939
} else {
4040
updateToast(t("storage.import_config_error"), "red");
41+
close();
4142
}
4243
});
4344
}

server/controller/config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ module.exports.getUsedStorage = async () => {
8383
module.exports.validateInput = async (key, value) => {
8484
if (!value?.toString()) return "You need to provide the new value";
8585

86-
if ((key === "ping" || key === "download" || key === "upload") && isNaN(value))
86+
if ((key === "ping" || key === "download" || key === "upload") && /[^0-9]/.test(value))
8787
return "You need to provide a number in order to change this";
8888

89-
if ((key === "ooklaId" || key === "libreId") && (isNaN(value) && value !== "none"))
89+
if ((key === "ooklaId" || key === "libreId") && (/[^0-9]/.test(value) && value !== "none"))
9090
return "You need to provide a number in order to change this";
9191

9292
if (key === "passwordLevel" && !["none", "read"].includes(value))

server/controller/pause.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ module.exports.updateState = (newState) => {
66
}
77

88
module.exports.resumeIn = (hours) => {
9-
if (isNaN(hours)) return;
9+
if (/[^0-9]/.test(hours)) return false;
10+
1011

1112
if (updateTimer !== null)
1213
clearTimeout(updateTimer);

server/routes/prometheus.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ app.get('/metrics', async (req, res) => {
4040
downloadGauge.set(latest.download);
4141
uploadGauge.set(latest.upload);
4242
currentServerGauge.set(latest.serverId);
43-
timeGauge.set(latest.time);
43+
44+
if (latest.time)
45+
timeGauge.set(latest.time);
4446

4547
res.set('Content-Type', promClient.register.contentType);
4648
res.end(await promClient.register.metrics());

server/routes/speedtests.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const testTask = require("../tasks/speedtest");
66
const password = require('../middlewares/password');
77

88
app.get("/", password(true), async (req, res) => {
9-
if (req.query.limit && isNaN(req.query.limit))
9+
if (req.query.limit && /[^0-9]/.test(req.query.limit))
1010
return res.status(400).json({message: "You need to provide a correct number in the limit parameter"});
1111

1212
res.json(await tests.listTests(req.query.hours || 24, req.query.start, req.query.limit));

server/routes/storage.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ app.delete("/tests/history", password(false), async (req, res) => {
3434
});
3535

3636
app.put("/tests/history", password(false), async (req, res) => {
37+
if (process.env.PREVIEW_MODE === "true")
38+
return res.status(403).json({message: "You can't import the tests in preview mode"});
39+
3740
let result = await tests.importTests(req.body);
3841
res.status(result ? 200 : 500).json({message: result ? "Tests imported" : "Error importing tests"});
3942
});
@@ -44,6 +47,8 @@ app.get("/config", password(false), async (req, res) => {
4447
});
4548

4649
app.put("/config", password(false), async (req, res) => {
50+
if (process.env.PREVIEW_MODE === "true")
51+
return res.status(403).json({message: "You can't import the config in preview mode"});
4752
let result = await config.importConfig(req.body);
4853
res.status(result ? 200 : 500).json({message: result ? "Config imported" : "Error importing config"});
4954
});

server/tasks/speedtest.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ module.exports.create = async (type = "auto", retried = false) => {
8888
await new Promise(resolve => setTimeout(resolve, 5000));
8989
test = {
9090
ping: {latency: Math.floor(Math.random() * 25) + 5},
91-
download: {bytes: Math.floor(Math.random() * 1000000000) + 1000000, elapsed: 10000},
92-
upload: {bytes: Math.floor(Math.random() * 1000000000) + 1000000, elapsed: 10000}
91+
download: {bandwidth: 125 * 100000 * (Math.random() + 0.5), elapsed: 10000},
92+
upload: {bandwidth: 125 * 100000 * (Math.random() + 0.5), elapsed: 10000},
9393
}
9494
} else {
9595
test = await this.run(retried);
@@ -104,6 +104,7 @@ module.exports.create = async (type = "auto", retried = false) => {
104104
setRunning(false);
105105
sendFinished({ping, download, upload, time}).then(() => "");
106106
} catch (e) {
107+
console.log(e)
107108
if (!retried) return this.create(type, true);
108109
let testResult = await tests.create(-1, -1, -1, null, 0, type, null, e.message);
109110
await sendError(e.message);

server/util/providers/parseData.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ module.exports.parseOokla = (test) => {
88
let upload = roundSpeed(test.upload.bandwidth);
99
let time = Math.round((test.download.elapsed + test.upload.elapsed) / 1000);
1010

11-
return {ping, download, upload, time, resultId: test.result.id};
11+
return {ping, download, upload, time, resultId: test.result?.id};
1212
}
1313

1414
module.exports.parseLibre = (test) => ({...test, ping: Math.round(test.ping), time: Math.round(test.elapsed / 1000),

0 commit comments

Comments
 (0)