mirror of
https://github.com/gnmyt/myspeed.git
synced 2026-01-07 21:49:48 -06:00
36 lines
924 B
JavaScript
36 lines
924 B
JavaScript
const config = require("../models/Config");
|
|
|
|
const configDefaults = {
|
|
"ping": "25",
|
|
"download": "100",
|
|
"upload": "50",
|
|
"timeLevel": "3",
|
|
"serverId": "none",
|
|
"password": "none"
|
|
}
|
|
|
|
module.exports.insertDefaults = async () => {
|
|
let insert = [];
|
|
for (let key in configDefaults) {
|
|
if (!(await config.findOne({where: {key: key}})))
|
|
insert.push({key: key, value: configDefaults[key]});
|
|
}
|
|
|
|
await config.bulkCreate(insert, {validate: true});
|
|
}
|
|
|
|
// Lists all config entries
|
|
module.exports.list = async () => {
|
|
return await config.findAll();
|
|
}
|
|
|
|
// Gets a specific config entry
|
|
module.exports.get = async (key) => {
|
|
return await config.findByPk(key);
|
|
}
|
|
|
|
// Updates a specific config entry
|
|
module.exports.update = async (key, newValue) => {
|
|
if (this.get(key) === undefined) return undefined;
|
|
return await config.update({value: newValue}, {where: {key: key}});
|
|
} |