mirror of
https://github.com/node-red/node-red.git
synced 2025-03-01 10:36:34 +00:00
Add "use strict" to most core nodes.
(skipping ones that may have other work in progress)
This commit is contained in:
@@ -15,16 +15,17 @@
|
||||
**/
|
||||
|
||||
module.exports = function(RED) {
|
||||
"use strict";
|
||||
var fs = require("fs");
|
||||
var spawn = require('child_process').spawn;
|
||||
|
||||
|
||||
function TailNode(n) {
|
||||
RED.nodes.createNode(this,n);
|
||||
|
||||
|
||||
this.filename = n.filename;
|
||||
this.split = n.split;
|
||||
var node = this;
|
||||
|
||||
|
||||
var err = "";
|
||||
var tail = spawn("tail", ["-f", this.filename]);
|
||||
tail.stdout.on("data", function (data) {
|
||||
@@ -43,15 +44,15 @@ module.exports = function(RED) {
|
||||
node.send(msg);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
tail.stderr.on("data", function(data) {
|
||||
node.warn(data.toString());
|
||||
});
|
||||
|
||||
|
||||
this.on("close", function() {
|
||||
if (tail) tail.kill();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
RED.nodes.registerType("tail",TailNode);
|
||||
}
|
||||
|
@@ -15,18 +15,19 @@
|
||||
**/
|
||||
|
||||
module.exports = function(RED) {
|
||||
"use strict";
|
||||
var fs = require("fs");
|
||||
|
||||
|
||||
function FileNode(n) {
|
||||
RED.nodes.createNode(this,n);
|
||||
|
||||
|
||||
this.filename = n.filename;
|
||||
this.appendNewline = n.appendNewline;
|
||||
this.overwriteFile = n.overwriteFile;
|
||||
var node = this;
|
||||
this.on("input",function(msg) {
|
||||
var filename = msg.filename || this.filename;
|
||||
|
||||
|
||||
if (filename == "") {
|
||||
node.warn('No filename specified');
|
||||
} else if (typeof msg.payload != "undefined") {
|
||||
@@ -60,10 +61,10 @@ module.exports = function(RED) {
|
||||
});
|
||||
}
|
||||
RED.nodes.registerType("file",FileNode);
|
||||
|
||||
|
||||
function FileInNode(n) {
|
||||
RED.nodes.createNode(this,n);
|
||||
|
||||
|
||||
this.filename = n.filename;
|
||||
this.format = n.format;
|
||||
var node = this;
|
||||
@@ -73,7 +74,7 @@ module.exports = function(RED) {
|
||||
}
|
||||
this.on("input",function(msg) {
|
||||
var filename = msg.filename || this.filename;
|
||||
|
||||
|
||||
if (filename == "") {
|
||||
node.warn('No filename specified');
|
||||
} else {
|
||||
|
@@ -105,9 +105,10 @@
|
||||
<div class="form-row">
|
||||
<label for="node-input-operation"><i class="icon-wrench"></i> Operation</label>
|
||||
<select type="text" id="node-input-operation" style="display: inline-block; vertical-align: top;">
|
||||
<option value=store>save</option>
|
||||
<option value=insert>insert</option>
|
||||
<option value=delete>remove</option>
|
||||
<option value="store">save</option>
|
||||
<option value="insert">insert</option>
|
||||
<option value="update">update</option>
|
||||
<option value="delete">remove</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="form-row node-input-payonly">
|
||||
|
@@ -15,9 +15,10 @@
|
||||
**/
|
||||
|
||||
module.exports = function(RED) {
|
||||
"use strict";
|
||||
var mongo = require('mongodb');
|
||||
var MongoClient = mongo.MongoClient;
|
||||
|
||||
|
||||
function MongoNode(n) {
|
||||
RED.nodes.createNode(this,n);
|
||||
this.hostname = n.hostname;
|
||||
@@ -29,20 +30,20 @@ module.exports = function(RED) {
|
||||
this.username = credentials.user;
|
||||
this.password = credentials.password;
|
||||
}
|
||||
|
||||
|
||||
var url = "mongodb://";
|
||||
if (this.username && this.password) {
|
||||
url += this.username+":"+this.password+"@";
|
||||
}
|
||||
url += this.hostname+":"+this.port+"/"+this.db;
|
||||
|
||||
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
|
||||
RED.nodes.registerType("mongodb",MongoNode);
|
||||
|
||||
|
||||
var querystring = require('querystring');
|
||||
|
||||
|
||||
RED.httpAdmin.get('/mongodb/:id',function(req,res) {
|
||||
var credentials = RED.nodes.getCredentials(req.params.id);
|
||||
if (credentials) {
|
||||
@@ -51,12 +52,12 @@ module.exports = function(RED) {
|
||||
res.send(JSON.stringify({}));
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
RED.httpAdmin.delete('/mongodb/:id',function(req,res) {
|
||||
RED.nodes.deleteCredentials(req.params.id);
|
||||
res.send(200);
|
||||
});
|
||||
|
||||
|
||||
RED.httpAdmin.post('/mongodb/:id',function(req,res) {
|
||||
var body = "";
|
||||
req.on('data', function(chunk) {
|
||||
@@ -79,8 +80,8 @@ module.exports = function(RED) {
|
||||
res.send(200);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
function MongoOutNode(n) {
|
||||
RED.nodes.createNode(this,n);
|
||||
this.collection = n.collection;
|
||||
@@ -88,7 +89,7 @@ module.exports = function(RED) {
|
||||
this.payonly = n.payonly || false;
|
||||
this.operation = n.operation;
|
||||
this.mongoConfig = RED.nodes.getNode(this.mongodb);
|
||||
|
||||
|
||||
if (this.mongoConfig) {
|
||||
var node = this;
|
||||
MongoClient.connect(this.mongoConfig.url, function(err,db) {
|
||||
@@ -116,6 +117,15 @@ module.exports = function(RED) {
|
||||
coll.insert(msg,function(err,item){if (err){node.error(err);}});
|
||||
}
|
||||
}
|
||||
else if (node.operation == "update") {
|
||||
delete msg._topic;
|
||||
if (node.payonly) {
|
||||
if (typeof msg.payload !== "object") { msg.payload = {"payload":msg.payload}; }
|
||||
coll.update(msg.payload,function(err,item){ if (err){node.error(err);} });
|
||||
} else {
|
||||
coll.update(msg,function(err,item){if (err){node.error(err);}});
|
||||
}
|
||||
}
|
||||
if (node.operation == "delete") {
|
||||
coll.remove(msg.payload, {w:1}, function(err, items){ if (err) node.error(err); });
|
||||
}
|
||||
@@ -125,7 +135,7 @@ module.exports = function(RED) {
|
||||
} else {
|
||||
this.error("missing mongodb configuration");
|
||||
}
|
||||
|
||||
|
||||
this.on("close", function() {
|
||||
if (this.clientDb) {
|
||||
this.clientDb.close();
|
||||
@@ -133,14 +143,14 @@ module.exports = function(RED) {
|
||||
});
|
||||
}
|
||||
RED.nodes.registerType("mongodb out",MongoOutNode);
|
||||
|
||||
|
||||
|
||||
|
||||
function MongoInNode(n) {
|
||||
RED.nodes.createNode(this,n);
|
||||
this.collection = n.collection;
|
||||
this.mongodb = n.mongodb;
|
||||
this.mongoConfig = RED.nodes.getNode(this.mongodb);
|
||||
|
||||
|
||||
if (this.mongoConfig) {
|
||||
var node = this;
|
||||
MongoClient.connect(this.mongoConfig.url, function(err,db) {
|
||||
@@ -168,7 +178,7 @@ module.exports = function(RED) {
|
||||
} else {
|
||||
this.error("missing mongodb configuration");
|
||||
}
|
||||
|
||||
|
||||
this.on("close", function() {
|
||||
if (this.clientDb) {
|
||||
this.clientDb.close();
|
||||
|
Reference in New Issue
Block a user