Compare commits

...

2 Commits

Author SHA1 Message Date
Logan Cusano
84aa4c5aff #15
- Changed the regex expression to not require a value after the key
2024-03-09 15:09:42 -05:00
Logan Cusano
32f827fe5e Fixing a bug in boot
- When booting for the first time, the generated NUID was saved to the wrong key
2024-03-08 23:36:02 -05:00
2 changed files with 14 additions and 14 deletions

View File

@@ -24,15 +24,13 @@ async function boot() {
*/ */
async function firstTimeBoot() { async function firstTimeBoot() {
// Generate a new ID for the node // Generate a new ID for the node
localNodeConfig.node.id = generateUniqueID(); localNodeConfig.node.nuid = await generateUniqueID();
console.log(`Generated a new unique ID for this node: '${localNodeConfig.node.nuid}'`); console.log(`Generated a new unique ID for this node: '${localNodeConfig.node.nuid}'`);
// Update the config with the new ID // Update the config with the new ID
updateId(localNodeConfig.node.nuid); await updateId(localNodeConfig.node.nuid);
console.log("Updated the config with the new node ID"); console.log("Updated the config with the new node ID");
// TODO - Create the config file with the ID given and replace the update above // TODO - Create the config file with the ID given and replace the update above
// TODO - Check if the system is linux or windows and set the 'type' param in DAB
// TODO - Implement web server so users can update radio systems easily // TODO - Implement web server so users can update radio systems easily
// TODO - Implement logic to check if the presets are set // TODO - Implement logic to check if the presets are set
return return

View File

@@ -3,9 +3,9 @@ import replace from 'replace-in-file';
class Options { class Options {
constructor(key, updatedValue) { constructor(key, updatedValue) {
this.files = "./.env"; this.files = ".env";
// A regex of the line containing the key in the config file // A regex of the line containing the key in the config file
this.from = new RegExp(`${key}="?(.+)"?`, "g"); this.from = new RegExp(`${key}="?(.+)?"?`, "g");
// Check to see if the value is a string and needs to be wrapped in double quotes // Check to see if the value is a string and needs to be wrapped in double quotes
if (Array(["string", "number"]).includes(typeof updatedValue)) this.to = `${key}="${updatedValue}",`; if (Array(["string", "number"]).includes(typeof updatedValue)) this.to = `${key}="${updatedValue}",`;
else this.to = `${key}=${updatedValue}`; else this.to = `${key}=${updatedValue}`;
@@ -16,10 +16,10 @@ class Options {
* Wrapper to update the client's saved ID * Wrapper to update the client's saved ID
* @param updatedId The updated ID assigned to the node * @param updatedId The updated ID assigned to the node
*/ */
export function updateId (updatedId) { export const updateId = async (updatedId) => {
updateConfig('CLIENT_NUID', updatedId); await updateConfig('CLIENT_NUID', updatedId);
process.env.CLIENT_NUID = updatedId; process.env.CLIENT_NUID = updatedId;
console.log("Updated ID to: ", updatedId); console.log("Updated NUID to: ", updatedId);
} }
/** /**
@@ -27,7 +27,7 @@ export function updateId (updatedId) {
* *
* @param {Object} runningConfig Running config object * @param {Object} runningConfig Running config object
* @param {Object} newConfigObject Object with what keys you wish to update (node object format, will be converted) * @param {Object} newConfigObject Object with what keys you wish to update (node object format, will be converted)
* @param {number} newConfigObject.id The ID given to the node to update * @param {number} newConfigObject.nuid The ID given to the node to update
* @param {string} newConfigObject.name The name of the node * @param {string} newConfigObject.name The name of the node
* @param {string} newConfigObject.ip The IP the server can contact the node on * @param {string} newConfigObject.ip The IP the server can contact the node on
* @param {number} newConfigObject.port The port the server can contact the node on * @param {number} newConfigObject.port The port the server can contact the node on
@@ -38,10 +38,10 @@ export function updateClientConfig (runningConfig, newConfigObject) {
var updatedKeys = [] var updatedKeys = []
const configKeys = Object.keys(newConfigObject); const configKeys = Object.keys(newConfigObject);
if (configKeys.includes("id")) { if (configKeys.includes("nuid")) {
if (runningConfig.id != newConfigObject.id) { if (runningConfig.nuid != newConfigObject.nuid) {
this.updateId(newConfigObject.id); this.updateId(newConfigObject.nuid);
updatedKeys.push({ 'CLIENT_NUID': newConfigObject.id }); updatedKeys.push({ 'CLIENT_NUID': newConfigObject.nuid });
} }
} }
if (configKeys.includes("name")) { if (configKeys.includes("name")) {
@@ -88,6 +88,8 @@ export function updateClientConfig (runningConfig, newConfigObject) {
export function updateConfig (key, value) { export function updateConfig (key, value) {
const options = new Options(key, value); const options = new Options(key, value);
console.log("Options:", options);
updateConfigFile(options, (updatedFiles) => { updateConfigFile(options, (updatedFiles) => {
// Do Something // Do Something
}) })