Finalizing Server webUI
Still needed: - Way to update clients' versions - Way to delete nodes - working dashboard - working search function
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
const { DebugBuilder } = require("../utilities/debugBuilder.js");
|
||||
const log = new DebugBuilder("client", "configController");
|
||||
// Modules
|
||||
const { nodeObject } = require("./utilities.js");
|
||||
const { getPresets } = require("../utilities/updatePresets");
|
||||
const { readFileSync } = require('fs');
|
||||
const path = require("path");
|
||||
require('dotenv').config();
|
||||
@@ -33,4 +35,8 @@ function getDeviceName(){
|
||||
log.DEBUG("Device Name: ", DeviceName);
|
||||
return DeviceName;
|
||||
}
|
||||
exports.getDeviceName = getDeviceID;
|
||||
exports.getDeviceName = getDeviceID;
|
||||
|
||||
exports.getFullConfig = () => {
|
||||
return new nodeObject({_id: process.env.CLIENT_ID, _ip: process.env.CLIENT_IP, _name: process.env.CLIENT_NAME, _port: process.env.CLIENT_PORT, _location: process.env.CLIENT_LOCATION, _nearbySystems: getPresets()});
|
||||
}
|
||||
@@ -9,7 +9,7 @@ const { isJsonString } = require("./utilities.js");
|
||||
|
||||
exports.requestOptions = class requestOptions {
|
||||
constructor(path, method, hostname = undefined, headers = undefined, port = undefined) {
|
||||
if (method === "POST"){
|
||||
if (["POST", "PUT"].includes(method)){
|
||||
log.VERBOSE("Hostname Vars: ", hostname, process.env.SERVER_HOSTNAME, process.env.SERVER_IP);
|
||||
if (hostname) this.hostname = hostname;
|
||||
if (process.env.SERVER_HOSTNAME) this.hostname = process.env.SERVER_HOSTNAME;
|
||||
|
||||
@@ -3,6 +3,7 @@ const { DebugBuilder } = require("../utilities/debugBuilder.js");
|
||||
const log = new DebugBuilder("client", "updateConfig");
|
||||
// Modules
|
||||
const replace = require('replace-in-file');
|
||||
const { getFullConfig } = require("./configHandler.js");
|
||||
|
||||
class Options {
|
||||
constructor(key, updatedValue) {
|
||||
@@ -23,6 +24,56 @@ exports.updateId = (updatedId) => {
|
||||
this.updateConfig('CLIENT_ID', updatedId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper to update any or all keys in the client config
|
||||
*
|
||||
* @param {*} configObject Object with what keys you wish to update (node object format, will be converted)
|
||||
* @returns
|
||||
*/
|
||||
exports.updateClientConfig = (configObject) => {
|
||||
const runningConfig = getFullConfig();
|
||||
var updatedKeys = []
|
||||
const configKeys = Object.keys(configObject);
|
||||
|
||||
if (configKeys.includes("id")) {
|
||||
if (runningConfig.id != configObject.id) {
|
||||
this.updateConfig('CLIENT_ID', configObject.id);
|
||||
updatedKeys.push({'CLIENT_ID': configObject.id});
|
||||
log.DEBUG("Updated ID to: ", configObject.id);
|
||||
}
|
||||
}
|
||||
if (configKeys.includes("name")) {
|
||||
if (runningConfig.name != configObject.name) {
|
||||
this.updateConfig('CLIENT_NAME', configObject.name);
|
||||
updatedKeys.push({'CLIENT_NAME': configObject.name});
|
||||
log.DEBUG("Updated name to: ", configObject.name);
|
||||
}
|
||||
}
|
||||
if (configKeys.includes("ip")) {
|
||||
if (runningConfig.ip != configObject.ip) {
|
||||
this.updateConfig('CLIENT_IP', configObject.ip);
|
||||
updatedKeys.push({'CLIENT_IP': configObject.ip});
|
||||
log.DEBUG("Updated ip to: ", configObject.ip);
|
||||
}
|
||||
}
|
||||
if (configKeys.includes("port")) {
|
||||
if (runningConfig.port != configObject.port) {
|
||||
this.updateConfig('CLIENT_PORT', configObject.port);
|
||||
updatedKeys.push({'CLIENT_PORT': configObject.port});
|
||||
log.DEBUG("Updated port to: ", configObject.port);
|
||||
}
|
||||
}
|
||||
if (configKeys.includes("location")) {
|
||||
if (runningConfig.location != configObject.location) {
|
||||
this.updateConfig('CLIENT_LOCATION', configObject.location);
|
||||
updatedKeys.push({'CLIENT_LOCATION': configObject.location});
|
||||
log.DEBUG("Updated location to: ", configObject.location);
|
||||
}
|
||||
}
|
||||
|
||||
return updatedKeys;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string} key The config file key to update with the value
|
||||
@@ -37,7 +88,6 @@ exports.updateConfig = function updateConfig(key, value) {
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Wrapper to write changes to the file
|
||||
* @param options An instance of the Objects class specified to the key being updated
|
||||
|
||||
@@ -25,17 +25,15 @@ exports.nodeObject = class nodeObject {
|
||||
* @param {*} param0._ip The IP that the master can contact the node at
|
||||
* @param {*} param0._port The port that the client is listening on
|
||||
* @param {*} param0._location The physical location of the node
|
||||
* @param {*} param0._online An integer representation of the online status of the bot, ie 0=off, 1=on
|
||||
* @param {*} param0._nearbySystems An object array of nearby systems
|
||||
*/
|
||||
constructor({ _id = null, _name = null, _ip = null, _port = null, _location = null, _nearbySystems = null, _online = null }) {
|
||||
constructor({ _id = null, _name = null, _ip = null, _port = null, _location = null, _nearbySystems = null }) {
|
||||
this.id = _id;
|
||||
this.name = _name;
|
||||
this.ip = _ip;
|
||||
this.port = _port;
|
||||
this.location = _location;
|
||||
this.nearbySystems = _nearbySystems;
|
||||
this.online = _online;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user