Potential final fix for #30

This commit is contained in:
Logan Cusano
2023-06-23 17:48:28 -04:00
parent 47d18c494d
commit 7163df21e9
4 changed files with 48 additions and 34 deletions

View File

@@ -35,7 +35,7 @@ exports.newNode = async (req, res) => {
_port: req.body.port ?? null,
_location: req.body.location ?? null,
_nearbySystems: req.body.nearbySystems ?? null,
_online: req.body.online ?? 0
_online: (req.body.online == "true" || req.body.online == "True") ? true : false
});
addNewNode(newNode, (newNodeObject) => {
@@ -65,53 +65,62 @@ exports.getNodeInfo = async (req, res) => {
exports.nodeCheckIn = async (req, res) => {
if (!req.body.id) return res.status(400).json("No id specified");
getNodeInfoFromId(req.body.id, (nodeInfo) => {
let checkInObject = new nodeObject({});
let checkInObject = {};
// Convert the online status to a boolean to be worked with
nodeInfo.online = nodeInfo.online !== 0;
log.DEBUG("REQ Body: ", req.body);
var isObjectUpdated = false;
if (req.body.name && req.body.name != nodeInfo.name) {
checkInObject.name = req.body.name;
checkInObject._name = req.body.name;
isObjectUpdated = true;
}
if (req.body.ip && req.body.ip != nodeInfo.ip) {
checkInObject.ip = req.body.ip;
checkInObject._ip = req.body.ip;
isObjectUpdated = true;
}
if (req.body.port && req.body.port != nodeInfo.port) {
checkInObject.port = req.body.port;
checkInObject._port = req.body.port;
isObjectUpdated = true;
}
if (req.body.location && req.body.location != nodeInfo.location) {
checkInObject.location = req.body.location;
checkInObject._location = req.body.location;
isObjectUpdated = true;
}
if (req.body.nearbySystems && JSON.stringify(req.body.nearbySystems) !== JSON.stringify(nodeInfo.nearbySystems)) {
checkInObject.nearbySystems = req.body.nearbySystems;
checkInObject._nearbySystems = req.body.nearbySystems;
isObjectUpdated = true;
}
if (req.body.online && (req.body.online === "true") != nodeInfo.online) {
checkInObject.online = (req.body.online === "true");
if (req.body.online != nodeInfo.online || req.body.online && (req.body.online === "true") != nodeInfo.online) {
checkInObject._online = req.body.online;
isObjectUpdated = true;
}
// If no changes are made tell the client
if (!isObjectUpdated) return res.status(200).json("No keys updated");
if (!isObjectUpdated) return res.status(200).json("No keys updated");
log.INFO("Updating the following keys for ID: ", req.body.id, checkInObject);
// Adding the ID key to the body so that the client can double-check their ID
checkInObject.id = nodeInfo.id;
updateNodeInfo(checkInObject, () => {
return res.status(202).json({"updatedKeys": checkInObject});
})
})
log.INFO("Updating the following keys for ID: ", req.body.id, checkInObject);
checkInObject._id = req.body.id;
checkInObject = new nodeObject(checkInObject);
if (!nodeInfo) {
log.WARN("No existing node found with this ID, adding node: ", checkInObject);
addNewNode(checkInObject, (newNode) => {
return res.status(201).json({"updatedKeys": newNode});
});
}
else {
updateNodeInfo(checkInObject, () => {
return res.status(202).json({"updatedKeys": checkInObject});
});
}
});
}
/**
@@ -123,7 +132,7 @@ exports.nodeCheckIn = async (req, res) => {
*/
exports.requestNodeJoinServer = async (req, res) => {
if (!req.body.clientId || !req.body.channelId || !req.body.presetName) return res.status(400).json("Missing information in request, requires clientId, channelId, presetName");
await joinServerWrapper(req.body.presetName, req.body.channelId, req.body.clientId)
await joinServerWrapper(req.body.presetName, req.body.channelId, req.body.clientId);
}
/**