mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Installing a module returns module info
Removing a module checks module exists and checks type is not in use
This commit is contained in:
@@ -34,6 +34,7 @@ module.exports = {
|
||||
res.send(redNodes.getNodeConfigs());
|
||||
}
|
||||
},
|
||||
|
||||
post: function(req,res) {
|
||||
if (!settings.available()) {
|
||||
res.send(400,new Error("Settings unavailable").toString());
|
||||
@@ -55,7 +56,7 @@ module.exports = {
|
||||
return;
|
||||
}
|
||||
promise.then(function(info) {
|
||||
res.json(info);
|
||||
res.json(redNodes.getModuleInfo(node.module));
|
||||
}).otherwise(function(err) {
|
||||
if (err.code === 404) {
|
||||
res.send(404);
|
||||
|
@@ -55,20 +55,21 @@ function checkTypeInUse(id) {
|
||||
var nodeInfo = registry.getNodeInfo(id);
|
||||
if (!nodeInfo) {
|
||||
throw new Error("Unrecognised id: "+id);
|
||||
}
|
||||
var inUse = {};
|
||||
flows.each(function(n) {
|
||||
inUse[n.type] = (inUse[n.type]||0)+1;
|
||||
});
|
||||
var nodesInUse = [];
|
||||
nodeInfo.types.forEach(function(t) {
|
||||
if (inUse[t]) {
|
||||
nodesInUse.push(t);
|
||||
} else {
|
||||
var inUse = {};
|
||||
flows.each(function(n) {
|
||||
inUse[n.type] = (inUse[n.type]||0)+1;
|
||||
});
|
||||
var nodesInUse = [];
|
||||
nodeInfo.types.forEach(function(t) {
|
||||
if (inUse[t]) {
|
||||
nodesInUse.push(t);
|
||||
}
|
||||
});
|
||||
if (nodesInUse.length > 0) {
|
||||
var msg = nodesInUse.join(", ");
|
||||
throw new Error("Type in use: "+msg);
|
||||
}
|
||||
});
|
||||
if (nodesInUse.length > 0) {
|
||||
var msg = nodesInUse.join(", ");
|
||||
throw new Error("Type in use: "+msg);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,13 +80,16 @@ function removeNode(id) {
|
||||
|
||||
function removeModule(module) {
|
||||
var info = registry.getNodeModuleInfo(module);
|
||||
for (var i=0;i<info.nodes.length;i++) {
|
||||
checkTypeInUse(info.nodes[i]);
|
||||
if (!info) {
|
||||
throw new Error("Unrecognised module: "+module);
|
||||
} else {
|
||||
for (var i=0;i<info.nodes.length;i++) {
|
||||
checkTypeInUse(module+"/"+info.nodes[i]);
|
||||
}
|
||||
return registry.removeModule(module);
|
||||
}
|
||||
return registry.removeModule(module);
|
||||
}
|
||||
|
||||
|
||||
function disableNode(id) {
|
||||
checkTypeInUse(id);
|
||||
return registry.disableNode(id);
|
||||
|
Reference in New Issue
Block a user