Update client clientController to better handle no ID
This commit is contained in:
@@ -67,6 +67,11 @@ async function checkLocalIP() {
|
|||||||
* Checks the config file for all required fields or gets and updates the required fields
|
* Checks the config file for all required fields or gets and updates the required fields
|
||||||
*/
|
*/
|
||||||
exports.checkConfig = async function checkConfig() {
|
exports.checkConfig = async function checkConfig() {
|
||||||
|
if (!runningClientConfig.id || runningClientConfig.id == 0 || runningClientConfig.id == '0') {
|
||||||
|
updateConfig('id', "");
|
||||||
|
runningClientConfig.id = null;
|
||||||
|
}
|
||||||
|
|
||||||
if (!runningClientConfig.ip) {
|
if (!runningClientConfig.ip) {
|
||||||
const ipAddr = await checkLocalIP();
|
const ipAddr = await checkLocalIP();
|
||||||
updateConfig('ip', ipAddr);
|
updateConfig('ip', ipAddr);
|
||||||
@@ -97,7 +102,7 @@ exports.checkIn = async () => {
|
|||||||
await this.checkConfig();
|
await this.checkConfig();
|
||||||
// Check if there is an ID found, if not add the node to the server. If there was an ID, check in with the server to make sure it has the correct information
|
// Check if there is an ID found, if not add the node to the server. If there was an ID, check in with the server to make sure it has the correct information
|
||||||
try {
|
try {
|
||||||
if (runningClientConfig.id === 0) {
|
if (!runningClientConfig?.id || runningClientConfig.id == null) {
|
||||||
// ID was not found in the config, creating a new node
|
// ID was not found in the config, creating a new node
|
||||||
reqOptions = new requestOptions("/nodes/newNode", "POST");
|
reqOptions = new requestOptions("/nodes/newNode", "POST");
|
||||||
sendHttpRequest(reqOptions, JSON.stringify(), (responseObject) => {
|
sendHttpRequest(reqOptions, JSON.stringify(), (responseObject) => {
|
||||||
@@ -118,6 +123,7 @@ exports.checkIn = async () => {
|
|||||||
// ID is in the config, checking in with the server
|
// ID is in the config, checking in with the server
|
||||||
reqOptions = new requestOptions("/nodes/nodeCheckIn", "POST");
|
reqOptions = new requestOptions("/nodes/nodeCheckIn", "POST");
|
||||||
sendHttpRequest(reqOptions, JSON.stringify(runningClientConfig), (responseObject) => {
|
sendHttpRequest(reqOptions, JSON.stringify(runningClientConfig), (responseObject) => {
|
||||||
|
log.DEBUG("Check In Respose: ", responseObject);
|
||||||
if (responseObject.statusCode === 202) {
|
if (responseObject.statusCode === 202) {
|
||||||
// Server accepted an update
|
// Server accepted an update
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user