Finalizing Server webUI
Still needed: - Way to update clients' versions - Way to delete nodes - working dashboard - working search function
This commit is contained in:
@@ -86,6 +86,8 @@ exports.leaveServer = async (req, res) => {
|
||||
const currentConnection = await getConnectionByNodeId(nodeId);
|
||||
log.DEBUG("Current Connection for node: ", currentConnection);
|
||||
|
||||
if (!currentConnection) return res.status(400).json("Node is not connected")
|
||||
|
||||
await leaveServerWrapper(currentConnection.clientObject)
|
||||
|
||||
return res.status(200).json(currentConnection.clientObject.name);
|
||||
|
||||
@@ -20,7 +20,7 @@ async function checkInWithNode(node) {
|
||||
sendHttpRequest(reqOptions, "", (responseObj) => {
|
||||
if (responseObj) {
|
||||
log.DEBUG("Response from: ", node.name, responseObj);
|
||||
const onlineNode = new nodeObject({ _online: false, _id: node.id });
|
||||
const onlineNode = new nodeObject({ _online: true, _id: node.id });
|
||||
log.DEBUG("Node update object: ", onlineNode);
|
||||
updateNodeInfo(onlineNode, (sqlResponse) => {
|
||||
if (!sqlResponse) this.log.ERROR("No response from SQL object");
|
||||
@@ -193,6 +193,39 @@ exports.updateNodeSystem = async (req, res) => {
|
||||
})
|
||||
}
|
||||
|
||||
/** Deletes a specific system/preset from a given node
|
||||
*
|
||||
* @param {*} req Default express req from router
|
||||
* @param {*} res Defualt express res from router
|
||||
* @param {*} req.params.nodeId The Node ID to update the preset/system on
|
||||
* @param {*} req.body.systemName The name of the system to update
|
||||
*/
|
||||
exports.removeNodeSystem = async (req, res) => {
|
||||
if (!req.params.nodeId) return res.status(400).json("No id specified");
|
||||
if (!req.body.systemName) return res.status(400).json("No system specified");
|
||||
log.DEBUG("Updating system for node: ", req.params.nodeId, req.body);
|
||||
getNodeInfoFromId(req.params.nodeId, (node) => {
|
||||
const reqOptions = new requestOptions("/client/removePreset", "POST", node.ip, node.port);
|
||||
const reqBody = {
|
||||
'systemName': req.body.systemName
|
||||
}
|
||||
|
||||
log.DEBUG("Request body for deleting preset: ", reqBody, reqOptions);
|
||||
sendHttpRequest(reqOptions, JSON.stringify(reqBody), async (responseObj) => {
|
||||
if(responseObj){
|
||||
// Good
|
||||
log.DEBUG("Response from deleting preset: ", reqBody, responseObj);
|
||||
return res.sendStatus(200)
|
||||
} else {
|
||||
// Bad
|
||||
log.DEBUG("No Response from deleting preset");
|
||||
return res.status(400).json("No Response from deleting preset, could be offline");
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
/** Updates the information received from the client based on ID
|
||||
*
|
||||
* @param {*} req Default express req from router
|
||||
@@ -247,14 +280,14 @@ exports.updateExistingNode = async = (req, res) => {
|
||||
|
||||
if (!nodeInfo) {
|
||||
log.WARN("No existing node found with this ID, adding node: ", checkInObject);
|
||||
addNewNode(checkInObject, (newNode) => {
|
||||
this.requestNodeCheckIn({"params": {"nodeId": checkInObject.id}});
|
||||
addNewNode(checkInObject, async (newNode) => {
|
||||
await checkInWithNode(newNode);
|
||||
return res.status(201).json({ "updatedKeys": newNode });
|
||||
});
|
||||
}
|
||||
else {
|
||||
updateNodeInfo(checkInObject, () => {
|
||||
this.requestNodeCheckIn({"params": {"nodeId": checkInObject.id}});
|
||||
updateNodeInfo(checkInObject, async () => {
|
||||
await checkInWithNode(nodeInfo);
|
||||
return res.status(202).json({ "updatedKeys": checkInObject });
|
||||
});
|
||||
}
|
||||
@@ -291,7 +324,7 @@ exports.requestNodeCheckIn = async (req, res) => {
|
||||
const node = await getNodeInfoFromId(req.params.nodeId);
|
||||
if (!node) return res.status(400).json("No Node with the ID given");
|
||||
await checkInWithNode(node);
|
||||
res.sendStatus(200);
|
||||
if (res) res.sendStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user