mirror of
https://github.com/gnmyt/myspeed.git
synced 2026-01-08 22:19:46 -06:00
Implemented the interface variable in the config.js
This commit is contained in:
@@ -10,6 +10,7 @@ const cron = require('cron-validator');
|
||||
const db = require("../config/database");
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const interfaces = require('../util/loadInterfaces');
|
||||
|
||||
const configDefaults = {
|
||||
ping: "25",
|
||||
@@ -20,14 +21,23 @@ const configDefaults = {
|
||||
ooklaId: "none",
|
||||
libreId: "none",
|
||||
password: "none",
|
||||
passwordLevel: "none"
|
||||
passwordLevel: "none",
|
||||
interface: "none"
|
||||
}
|
||||
|
||||
module.exports.insertDefaults = async () => {
|
||||
let insert = [];
|
||||
for (let key in configDefaults) {
|
||||
if (!(await config.findOne({where: {key: key}})))
|
||||
if (key !== "interface" && !(await config.findOne({where: {key: key}})))
|
||||
insert.push({key: key, value: configDefaults[key]});
|
||||
|
||||
if (key === "interface") {
|
||||
const ips = Object.keys(interfaces.interfaces);
|
||||
let ip = ips.length > 0 ? ips[0] : "none";
|
||||
|
||||
if (!(await config.findOne({where: {key: key}})))
|
||||
insert.push({key: key, value: ip});
|
||||
}
|
||||
}
|
||||
|
||||
await config.bulkCreate(insert, {validate: true});
|
||||
@@ -94,6 +104,9 @@ module.exports.validateInput = async (key, value) => {
|
||||
if (key === "cron" && !cron.isValidCron(value.toString()))
|
||||
return "Not a valid cron expression";
|
||||
|
||||
if (key === "interface" && !Object.keys(interfaces.interfaces).includes(value))
|
||||
return "The provided interface does not exist";
|
||||
|
||||
if (configDefaults[key] === undefined)
|
||||
return "The provided key does not exist";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user