mirror of
https://github.com/node-red/node-red-nodes.git
synced 2025-03-01 10:37:43 +00:00
Update node-red-nodes social nodes to use strict and pass jshint scan
This commit is contained in:
parent
9b487098ae
commit
62956b0bb8
@ -14,11 +14,12 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
**/
|
**/
|
||||||
|
|
||||||
var RED = require(process.env.NODE_RED_HOME+"/red/red");
|
module.exports = function(RED) {
|
||||||
var nma = require('nma');
|
"use strict";
|
||||||
var util = require('util');
|
var nma = require('nma');
|
||||||
|
var util = require('util');
|
||||||
|
|
||||||
function NMANode(n) {
|
function NMANode(n) {
|
||||||
RED.nodes.createNode(this,n);
|
RED.nodes.createNode(this,n);
|
||||||
this.title = n.title;
|
this.title = n.title;
|
||||||
var credentials = RED.nodes.getCredentials(n.id);
|
var credentials = RED.nodes.getCredentials(n.id);
|
||||||
@ -42,27 +43,27 @@ function NMANode(n) {
|
|||||||
node.warn("NMA credentials not set.");
|
node.warn("NMA credentials not set.");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
RED.nodes.registerType("nma",NMANode);
|
RED.nodes.registerType("nma",NMANode);
|
||||||
|
|
||||||
var querystring = require('querystring');
|
var querystring = require('querystring');
|
||||||
|
|
||||||
RED.httpAdmin.get('/nma/:id',function(req,res) {
|
RED.httpAdmin.get('/nma/:id',function(req,res) {
|
||||||
var credentials = RED.nodes.getCredentials(req.params.id);
|
var credentials = RED.nodes.getCredentials(req.params.id);
|
||||||
if (credentials) {
|
if (credentials) {
|
||||||
res.send(JSON.stringify({hasPassword:(credentials.pushkey&&credentials.pushkey!="")}));
|
res.send(JSON.stringify({hasPassword:(credentials.pushkey&&credentials.pushkey!=="")}));
|
||||||
} else {
|
} else {
|
||||||
res.send(JSON.stringify({}));
|
res.send(JSON.stringify({}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
RED.httpAdmin.delete('/nma/:id',function(req,res) {
|
RED.httpAdmin.delete('/nma/:id',function(req,res) {
|
||||||
RED.nodes.deleteCredentials(req.params.id);
|
RED.nodes.deleteCredentials(req.params.id);
|
||||||
res.send(200);
|
res.send(200);
|
||||||
});
|
});
|
||||||
|
|
||||||
RED.httpAdmin.post('/nma/:id',function(req,res) {
|
RED.httpAdmin.post('/nma/:id',function(req,res) {
|
||||||
var body = "";
|
var body = "";
|
||||||
req.on('data', function(chunk) {
|
req.on('data', function(chunk) {
|
||||||
body+=chunk;
|
body+=chunk;
|
||||||
@ -70,7 +71,7 @@ RED.httpAdmin.post('/nma/:id',function(req,res) {
|
|||||||
req.on('end', function(){
|
req.on('end', function(){
|
||||||
var newCreds = querystring.parse(body);
|
var newCreds = querystring.parse(body);
|
||||||
var credentials = RED.nodes.getCredentials(req.params.id)||{};
|
var credentials = RED.nodes.getCredentials(req.params.id)||{};
|
||||||
if (newCreds.pushkey == "") {
|
if (newCreds.pushkey === "") {
|
||||||
delete credentials.pushkey;
|
delete credentials.pushkey;
|
||||||
} else {
|
} else {
|
||||||
credentials.pushkey = newCreds.pushkey||credentials.pushkey;
|
credentials.pushkey = newCreds.pushkey||credentials.pushkey;
|
||||||
@ -78,4 +79,5 @@ RED.httpAdmin.post('/nma/:id',function(req,res) {
|
|||||||
RED.nodes.addCredentials(req.params.id,credentials);
|
RED.nodes.addCredentials(req.params.id,credentials);
|
||||||
res.send(200);
|
res.send(200);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
@ -14,11 +14,12 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
**/
|
**/
|
||||||
|
|
||||||
var RED = require(process.env.NODE_RED_HOME+"/red/red");
|
module.exports = function(RED) {
|
||||||
var growl = require('growl');
|
"use strict";
|
||||||
var imagefile = process.env.NODE_RED_HOME+"/public/node-red.png";
|
var growl = require('growl');
|
||||||
|
var imagefile = process.env.NODE_RED_HOME+"/public/node-red.png";
|
||||||
|
|
||||||
function NotifyNode(n) {
|
function NotifyNode(n) {
|
||||||
RED.nodes.createNode(this,n);
|
RED.nodes.createNode(this,n);
|
||||||
this.title = n.title;
|
this.title = n.title;
|
||||||
var node = this;
|
var node = this;
|
||||||
@ -34,6 +35,7 @@ function NotifyNode(n) {
|
|||||||
growl(msg.payload, { image: imagefile });
|
growl(msg.payload, { image: imagefile });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
RED.nodes.registerType("notify",NotifyNode);
|
RED.nodes.registerType("notify",NotifyNode);
|
||||||
|
}
|
||||||
|
@ -14,26 +14,27 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
**/
|
**/
|
||||||
|
|
||||||
var RED = require(process.env.NODE_RED_HOME+"/red/red");
|
module.exports = function(RED) {
|
||||||
var Prowl = require('node-prowl');
|
"use strict";
|
||||||
var util = require('util');
|
var Prowl = require('node-prowl');
|
||||||
|
var util = require('util');
|
||||||
|
|
||||||
// Either add a line like this to settings.js
|
// Either add a line like this to settings.js
|
||||||
// prowl: {prowlkey:'My-API-KEY'},
|
// prowl: {prowlkey:'My-API-KEY'},
|
||||||
// or create pushkey.js in dir ABOVE node-red, it just needs to be like
|
// or create pushkey.js in dir ABOVE node-red, it just needs to be like
|
||||||
// module.exports = {prowlkey:'My-API-KEY'}
|
// module.exports = {prowlkey:'My-API-KEY'}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var pushkeys = RED.settings.prowl || require(process.env.NODE_RED_HOME+"/../pushkey.js");
|
var pushkeys = RED.settings.prowl || require(process.env.NODE_RED_HOME+"/../pushkey.js");
|
||||||
}
|
}
|
||||||
catch(err) { }
|
catch(err) { }
|
||||||
|
|
||||||
function ProwlNode(n) {
|
function ProwlNode(n) {
|
||||||
RED.nodes.createNode(this,n);
|
RED.nodes.createNode(this,n);
|
||||||
this.title = n.title;
|
this.title = n.title;
|
||||||
this.priority = parseInt(n.priority);
|
this.priority = parseInt(n.priority);
|
||||||
if (this.priority > 2) this.priority = 2;
|
if (this.priority > 2) { this.priority = 2; }
|
||||||
if (this.priority < -2) this.priority = -2;
|
if (this.priority < -2) { this.priority = -2; }
|
||||||
var credentials = RED.nodes.getCredentials(n.id);
|
var credentials = RED.nodes.getCredentials(n.id);
|
||||||
if ((credentials) && (credentials.hasOwnProperty("pushkey"))) { this.pushkey = credentials.pushkey; }
|
if ((credentials) && (credentials.hasOwnProperty("pushkey"))) { this.pushkey = credentials.pushkey; }
|
||||||
else {
|
else {
|
||||||
@ -54,7 +55,7 @@ function ProwlNode(n) {
|
|||||||
if (node.pushkey) {
|
if (node.pushkey) {
|
||||||
try {
|
try {
|
||||||
node.prowl.push(msg.payload, titl, { priority: pri }, function(err, remaining) {
|
node.prowl.push(msg.payload, titl, { priority: pri }, function(err, remaining) {
|
||||||
if (err) node.error(err);
|
if (err) { node.error(err); }
|
||||||
node.log( remaining + ' calls to Prowl api during current hour.' );
|
node.log( remaining + ' calls to Prowl api during current hour.' );
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -66,32 +67,32 @@ function ProwlNode(n) {
|
|||||||
node.warn("Prowl credentials not set.");
|
node.warn("Prowl credentials not set.");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
RED.nodes.registerType("prowl",ProwlNode);
|
RED.nodes.registerType("prowl",ProwlNode);
|
||||||
|
|
||||||
var querystring = require('querystring');
|
var querystring = require('querystring');
|
||||||
|
|
||||||
RED.httpAdmin.get('/prowl/:id',function(req,res) {
|
RED.httpAdmin.get('/prowl/:id',function(req,res) {
|
||||||
var credentials = RED.nodes.getCredentials(req.params.id);
|
var credentials = RED.nodes.getCredentials(req.params.id);
|
||||||
if (credentials) {
|
if (credentials) {
|
||||||
res.send(JSON.stringify({hasPassword:(credentials.pushkey&&credentials.pushkey!="")}));
|
res.send(JSON.stringify({hasPassword:(credentials.pushkey&&credentials.pushkey!=="")}));
|
||||||
}
|
}
|
||||||
else if (pushkeys && pushkeys.prowlkey) {
|
else if (pushkeys && pushkeys.prowlkey) {
|
||||||
RED.nodes.addCredentials(req.params.id,{pushkey:pushkeys.prowlkey,global:true});
|
RED.nodes.addCredentials(req.params.id,{pushkey:pushkeys.prowlkey,global:true});
|
||||||
credentials = RED.nodes.getCredentials(req.params.id);
|
credentials = RED.nodes.getCredentials(req.params.id);
|
||||||
res.send(JSON.stringify({hasPassword:(credentials.pushkey&&credentials.pushkey!=""),global:credentials.global}));;
|
res.send(JSON.stringify({hasPassword:(credentials.pushkey&&credentials.pushkey!==""),global:credentials.global}));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
res.send(JSON.stringify({}));
|
res.send(JSON.stringify({}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
RED.httpAdmin.delete('/prowl/:id',function(req,res) {
|
RED.httpAdmin.delete('/prowl/:id',function(req,res) {
|
||||||
RED.nodes.deleteCredentials(req.params.id);
|
RED.nodes.deleteCredentials(req.params.id);
|
||||||
res.send(200);
|
res.send(200);
|
||||||
});
|
});
|
||||||
|
|
||||||
RED.httpAdmin.post('/prowl/:id',function(req,res) {
|
RED.httpAdmin.post('/prowl/:id',function(req,res) {
|
||||||
var body = "";
|
var body = "";
|
||||||
req.on('data', function(chunk) {
|
req.on('data', function(chunk) {
|
||||||
body+=chunk;
|
body+=chunk;
|
||||||
@ -99,7 +100,7 @@ RED.httpAdmin.post('/prowl/:id',function(req,res) {
|
|||||||
req.on('end', function(){
|
req.on('end', function(){
|
||||||
var newCreds = querystring.parse(body);
|
var newCreds = querystring.parse(body);
|
||||||
var credentials = RED.nodes.getCredentials(req.params.id)||{};
|
var credentials = RED.nodes.getCredentials(req.params.id)||{};
|
||||||
if (newCreds.pushkey == "") {
|
if (newCreds.pushkey === "") {
|
||||||
delete credentials.pushkey;
|
delete credentials.pushkey;
|
||||||
} else {
|
} else {
|
||||||
credentials.pushkey = newCreds.pushkey||credentials.pushkey;
|
credentials.pushkey = newCreds.pushkey||credentials.pushkey;
|
||||||
@ -107,4 +108,5 @@ RED.httpAdmin.post('/prowl/:id',function(req,res) {
|
|||||||
RED.nodes.addCredentials(req.params.id,credentials);
|
RED.nodes.addCredentials(req.params.id,credentials);
|
||||||
res.send(200);
|
res.send(200);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
@ -14,22 +14,23 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
**/
|
**/
|
||||||
|
|
||||||
var RED = require(process.env.NODE_RED_HOME+"/red/red");
|
module.exports = function(RED) {
|
||||||
var PushBullet = require('pushbullet');
|
"use strict";
|
||||||
var util = require('util');
|
var PushBullet = require('pushbullet');
|
||||||
|
var util = require('util');
|
||||||
|
|
||||||
// Either create pushkey.js in dir ABOVE node-red, it just needs to be like
|
// Either create pushkey.js in dir ABOVE node-red, it just needs to be like
|
||||||
// module.exports = {pushbullet:'My-API-KEY', deviceid:'12345'}
|
// module.exports = {pushbullet:'My-API-KEY', deviceid:'12345'}
|
||||||
// or set them per node in the edit dialog
|
// or set them per node in the edit dialog
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var pushkeys = RED.settings.pushbullet || require(process.env.NODE_RED_HOME+"/../pushkey.js");
|
var pushkeys = RED.settings.pushbullet || require(process.env.NODE_RED_HOME+"/../pushkey.js");
|
||||||
}
|
}
|
||||||
catch(err) {
|
catch(err) {
|
||||||
//util.log("[57-pushbullet.js] Warning: Failed to load global PushBullet credentials");
|
//util.log("[57-pushbullet.js] Warning: Failed to load global PushBullet credentials");
|
||||||
}
|
}
|
||||||
|
|
||||||
function PushbulletNode(n) {
|
function PushbulletNode(n) {
|
||||||
RED.nodes.createNode(this,n);
|
RED.nodes.createNode(this,n);
|
||||||
this.title = n.title;
|
this.title = n.title;
|
||||||
var credentials = RED.nodes.getCredentials(n.id);
|
var credentials = RED.nodes.getCredentials(n.id);
|
||||||
@ -57,7 +58,7 @@ function PushbulletNode(n) {
|
|||||||
try {
|
try {
|
||||||
if (!isNaN(dev)) { dev = Number(dev); }
|
if (!isNaN(dev)) { dev = Number(dev); }
|
||||||
node.pusher.note(dev, titl, msg.payload, function(err, response) {
|
node.pusher.note(dev, titl, msg.payload, function(err, response) {
|
||||||
if (err) node.error("Pushbullet error: "+err);
|
if (err) { node.error("Pushbullet error: "+err); }
|
||||||
//console.log(response);
|
//console.log(response);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -69,32 +70,32 @@ function PushbulletNode(n) {
|
|||||||
node.warn("Pushbullet credentials not set/found. See node info.");
|
node.warn("Pushbullet credentials not set/found. See node info.");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
RED.nodes.registerType("pushbullet",PushbulletNode);
|
RED.nodes.registerType("pushbullet",PushbulletNode);
|
||||||
|
|
||||||
var querystring = require('querystring');
|
var querystring = require('querystring');
|
||||||
|
|
||||||
RED.httpAdmin.get('/pushbullet/:id',function(req,res) {
|
RED.httpAdmin.get('/pushbullet/:id',function(req,res) {
|
||||||
var credentials = RED.nodes.getCredentials(req.params.id);
|
var credentials = RED.nodes.getCredentials(req.params.id);
|
||||||
if (credentials) {
|
if (credentials) {
|
||||||
res.send(JSON.stringify({deviceid:credentials.deviceid,hasPassword:(credentials.pushkey&&credentials.pushkey!="")}));
|
res.send(JSON.stringify({deviceid:credentials.deviceid,hasPassword:(credentials.pushkey&&credentials.pushkey!=="")}));
|
||||||
}
|
}
|
||||||
else if (pushkeys && pushkeys.pushbullet && pushkeys.deviceid) {
|
else if (pushkeys && pushkeys.pushbullet && pushkeys.deviceid) {
|
||||||
RED.nodes.addCredentials(req.params.id,{pushkey:pushkeys.pushbullet,deviceid:pushkeys.deviceid,global:true});
|
RED.nodes.addCredentials(req.params.id,{pushkey:pushkeys.pushbullet,deviceid:pushkeys.deviceid,global:true});
|
||||||
credentials = RED.nodes.getCredentials(req.params.id);
|
credentials = RED.nodes.getCredentials(req.params.id);
|
||||||
res.send(JSON.stringify({deviceid:credentials.deviceid,global:credentials.global,hasPassword:(credentials.pushkey&&credentials.pushkey!="")}));;
|
res.send(JSON.stringify({deviceid:credentials.deviceid,global:credentials.global,hasPassword:(credentials.pushkey&&credentials.pushkey!=="")}));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
res.send(JSON.stringify({}));
|
res.send(JSON.stringify({}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
RED.httpAdmin.delete('/pushbullet/:id',function(req,res) {
|
RED.httpAdmin.delete('/pushbullet/:id',function(req,res) {
|
||||||
RED.nodes.deleteCredentials(req.params.id);
|
RED.nodes.deleteCredentials(req.params.id);
|
||||||
res.send(200);
|
res.send(200);
|
||||||
});
|
});
|
||||||
|
|
||||||
RED.httpAdmin.post('/pushbullet/:id',function(req,res) {
|
RED.httpAdmin.post('/pushbullet/:id',function(req,res) {
|
||||||
var body = "";
|
var body = "";
|
||||||
req.on('data', function(chunk) {
|
req.on('data', function(chunk) {
|
||||||
body+=chunk;
|
body+=chunk;
|
||||||
@ -102,12 +103,12 @@ RED.httpAdmin.post('/pushbullet/:id',function(req,res) {
|
|||||||
req.on('end', function(){
|
req.on('end', function(){
|
||||||
var newCreds = querystring.parse(body);
|
var newCreds = querystring.parse(body);
|
||||||
var credentials = RED.nodes.getCredentials(req.params.id)||{};
|
var credentials = RED.nodes.getCredentials(req.params.id)||{};
|
||||||
if (newCreds.deviceid == null || newCreds.deviceid == "") {
|
if (newCreds.deviceid === null || newCreds.deviceid === "") {
|
||||||
delete credentials.deviceid;
|
delete credentials.deviceid;
|
||||||
} else {
|
} else {
|
||||||
credentials.deviceid = newCreds.deviceid;
|
credentials.deviceid = newCreds.deviceid;
|
||||||
}
|
}
|
||||||
if (newCreds.pushkey == "") {
|
if (newCreds.pushkey === "") {
|
||||||
delete credentials.pushkey;
|
delete credentials.pushkey;
|
||||||
} else {
|
} else {
|
||||||
credentials.pushkey = newCreds.pushkey||credentials.pushkey;
|
credentials.pushkey = newCreds.pushkey||credentials.pushkey;
|
||||||
@ -115,4 +116,5 @@ RED.httpAdmin.post('/pushbullet/:id',function(req,res) {
|
|||||||
RED.nodes.addCredentials(req.params.id,credentials);
|
RED.nodes.addCredentials(req.params.id,credentials);
|
||||||
res.send(200);
|
res.send(200);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
@ -17,14 +17,12 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
**/
|
**/
|
||||||
|
module.exports = function(RED) {
|
||||||
|
"use strict";
|
||||||
|
var Pusher = require('pusher');
|
||||||
|
var PusherClient = require('pusher-client');
|
||||||
|
|
||||||
var Pusher = require('pusher');
|
//node for subscribing to an event/channel
|
||||||
var PusherClient = require('pusher-client');
|
|
||||||
|
|
||||||
// Require main module
|
|
||||||
var RED = require(process.env.NODE_RED_HOME+"/red/red");
|
|
||||||
|
|
||||||
//node for subscribing to an event/channel
|
|
||||||
function PusherNode(n) {
|
function PusherNode(n) {
|
||||||
// Create a RED node
|
// Create a RED node
|
||||||
RED.nodes.createNode(this,n);
|
RED.nodes.createNode(this,n);
|
||||||
@ -54,10 +52,10 @@ var RED = require(process.env.NODE_RED_HOME+"/red/red");
|
|||||||
this.on("close", function() {
|
this.on("close", function() {
|
||||||
socket.disconnect();
|
socket.disconnect();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
//Node for sending Pusher events
|
//Node for sending Pusher events
|
||||||
function PusherNodeSend(n) {
|
function PusherNodeSend(n) {
|
||||||
// Create a RED node
|
// Create a RED node
|
||||||
RED.nodes.createNode(this,n);
|
RED.nodes.createNode(this,n);
|
||||||
|
|
||||||
@ -93,34 +91,34 @@ function PusherNodeSend(n) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//debugging on the output:
|
//debugging on the output:
|
||||||
var displayResult = function(result) {
|
var displayResult = function(result) {
|
||||||
node.log(result);
|
node.log(result);
|
||||||
};
|
};
|
||||||
|
|
||||||
var displayError = function(err) {
|
var displayError = function(err) {
|
||||||
node.log("Error: "+err);
|
node.log("Error: "+err);
|
||||||
};
|
};
|
||||||
|
|
||||||
RED.nodes.registerType("pusher in",PusherNode);
|
RED.nodes.registerType("pusher in",PusherNode);
|
||||||
RED.nodes.registerType("pusher out",PusherNodeSend);
|
RED.nodes.registerType("pusher out",PusherNodeSend);
|
||||||
|
|
||||||
var querystring = require('querystring');
|
var querystring = require('querystring');
|
||||||
|
|
||||||
RED.httpAdmin.get('/pusher/:id',function(req,res) {
|
RED.httpAdmin.get('/pusher/:id',function(req,res) {
|
||||||
var credentials = RED.nodes.getCredentials(req.params.id);
|
var credentials = RED.nodes.getCredentials(req.params.id);
|
||||||
if (credentials) {
|
if (credentials) {
|
||||||
res.send(JSON.stringify({pusherappid:credentials.pusherappid,pusherappsecret:credentials.pusherappsecret, pusherappkey:credentials.pusherappkey, pusherappkey_sub:credentials.pusherappkey_sub}));
|
res.send(JSON.stringify({pusherappid:credentials.pusherappid,pusherappsecret:credentials.pusherappsecret, pusherappkey:credentials.pusherappkey, pusherappkey_sub:credentials.pusherappkey_sub}));
|
||||||
} else {
|
} else {
|
||||||
res.send(JSON.stringify({}));
|
res.send(JSON.stringify({}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
RED.httpAdmin.delete('/pusher/:id',function(req,res) {
|
RED.httpAdmin.delete('/pusher/:id',function(req,res) {
|
||||||
RED.nodes.deleteCredentials(req.params.id);
|
RED.nodes.deleteCredentials(req.params.id);
|
||||||
res.send(200);
|
res.send(200);
|
||||||
});
|
});
|
||||||
|
|
||||||
RED.httpAdmin.post('/pusher/:id',function(req,res) {
|
RED.httpAdmin.post('/pusher/:id',function(req,res) {
|
||||||
var body = "";
|
var body = "";
|
||||||
req.on('data', function(chunk) {
|
req.on('data', function(chunk) {
|
||||||
body+=chunk;
|
body+=chunk;
|
||||||
@ -129,24 +127,24 @@ RED.httpAdmin.post('/pusher/:id',function(req,res) {
|
|||||||
var newCreds = querystring.parse(body);
|
var newCreds = querystring.parse(body);
|
||||||
var credentials = RED.nodes.getCredentials(req.params.id)||{};
|
var credentials = RED.nodes.getCredentials(req.params.id)||{};
|
||||||
|
|
||||||
if (newCreds.pusherappid == null || newCreds.pusherappid == "") {
|
if (newCreds.pusherappid === null || newCreds.pusherappid === "") {
|
||||||
delete credentials.pusherappid;
|
delete credentials.pusherappid;
|
||||||
} else {
|
} else {
|
||||||
credentials.pusherappid = newCreds.pusherappid;
|
credentials.pusherappid = newCreds.pusherappid;
|
||||||
}
|
}
|
||||||
if (newCreds.pusherappkey == "") {
|
if (newCreds.pusherappkey === "") {
|
||||||
delete credentials.pusherappkey;
|
delete credentials.pusherappkey;
|
||||||
} else {
|
} else {
|
||||||
credentials.pusherappkey = newCreds.pusherappkey||credentials.pusherappkey;
|
credentials.pusherappkey = newCreds.pusherappkey||credentials.pusherappkey;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newCreds.pusherappsecret == "") {
|
if (newCreds.pusherappsecret === "") {
|
||||||
delete credentials.pusherappsecret;
|
delete credentials.pusherappsecret;
|
||||||
} else {
|
} else {
|
||||||
credentials.pusherappsecret = newCreds.pusherappsecret||credentials.pusherappsecret;
|
credentials.pusherappsecret = newCreds.pusherappsecret||credentials.pusherappsecret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newCreds.pusherappkey_sub == "") {
|
if (newCreds.pusherappkey_sub === "") {
|
||||||
delete credentials.pusherappkey_sub;
|
delete credentials.pusherappkey_sub;
|
||||||
} else {
|
} else {
|
||||||
credentials.pusherappkey_sub = newCreds.pusherappkey_sub||credentials.pusherappkey_sub;
|
credentials.pusherappkey_sub = newCreds.pusherappkey_sub||credentials.pusherappkey_sub;
|
||||||
@ -155,4 +153,5 @@ RED.httpAdmin.post('/pusher/:id',function(req,res) {
|
|||||||
RED.nodes.addCredentials(req.params.id,credentials);
|
RED.nodes.addCredentials(req.params.id,credentials);
|
||||||
res.send(200);
|
res.send(200);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
@ -14,11 +14,12 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
**/
|
**/
|
||||||
|
|
||||||
var RED = require(process.env.NODE_RED_HOME+"/red/red");
|
module.exports = function(RED) {
|
||||||
var PushOver = require('pushover-notifications');
|
"use strict";
|
||||||
var util = require('util');
|
var PushOver = require('pushover-notifications');
|
||||||
|
var util = require('util');
|
||||||
|
|
||||||
function PushoverNode(n) {
|
function PushoverNode(n) {
|
||||||
RED.nodes.createNode(this,n);
|
RED.nodes.createNode(this,n);
|
||||||
this.title = n.title;
|
this.title = n.title;
|
||||||
this.priority = n.priority;
|
this.priority = n.priority;
|
||||||
@ -59,7 +60,7 @@ function PushoverNode(n) {
|
|||||||
};
|
};
|
||||||
//console.log("Sending",pushmsg);
|
//console.log("Sending",pushmsg);
|
||||||
pusher.send( pushmsg, function(err, response) {
|
pusher.send( pushmsg, function(err, response) {
|
||||||
if (err) node.error("Pushover Error: "+err);
|
if (err) { node.error("Pushover Error: "+err); }
|
||||||
//console.log(response);
|
//console.log(response);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -67,26 +68,26 @@ function PushoverNode(n) {
|
|||||||
node.warn("Pushover credentials not set.");
|
node.warn("Pushover credentials not set.");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
RED.nodes.registerType("pushover",PushoverNode);
|
RED.nodes.registerType("pushover",PushoverNode);
|
||||||
|
|
||||||
var querystring = require('querystring');
|
var querystring = require('querystring');
|
||||||
|
|
||||||
RED.httpAdmin.get('/pushover/:id',function(req,res) {
|
RED.httpAdmin.get('/pushover/:id',function(req,res) {
|
||||||
var credentials = RED.nodes.getCredentials(req.params.id);
|
var credentials = RED.nodes.getCredentials(req.params.id);
|
||||||
if (credentials) {
|
if (credentials) {
|
||||||
res.send(JSON.stringify({deviceid:credentials.deviceid,hasPassword:(credentials.pushkey&&credentials.pushkey!="")}));
|
res.send(JSON.stringify({deviceid:credentials.deviceid,hasPassword:(credentials.pushkey&&credentials.pushkey!=="")}));
|
||||||
} else {
|
} else {
|
||||||
res.send(JSON.stringify({}));
|
res.send(JSON.stringify({}));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
RED.httpAdmin.delete('/pushover/:id',function(req,res) {
|
RED.httpAdmin.delete('/pushover/:id',function(req,res) {
|
||||||
RED.nodes.deleteCredentials(req.params.id);
|
RED.nodes.deleteCredentials(req.params.id);
|
||||||
res.send(200);
|
res.send(200);
|
||||||
});
|
});
|
||||||
|
|
||||||
RED.httpAdmin.post('/pushover/:id',function(req,res) {
|
RED.httpAdmin.post('/pushover/:id',function(req,res) {
|
||||||
var body = "";
|
var body = "";
|
||||||
req.on('data', function(chunk) {
|
req.on('data', function(chunk) {
|
||||||
body+=chunk;
|
body+=chunk;
|
||||||
@ -94,12 +95,12 @@ RED.httpAdmin.post('/pushover/:id',function(req,res) {
|
|||||||
req.on('end', function(){
|
req.on('end', function(){
|
||||||
var newCreds = querystring.parse(body);
|
var newCreds = querystring.parse(body);
|
||||||
var credentials = RED.nodes.getCredentials(req.params.id)||{};
|
var credentials = RED.nodes.getCredentials(req.params.id)||{};
|
||||||
if (newCreds.deviceid == null || newCreds.deviceid == "") {
|
if (newCreds.deviceid === null || newCreds.deviceid === "") {
|
||||||
delete credentials.deviceid;
|
delete credentials.deviceid;
|
||||||
} else {
|
} else {
|
||||||
credentials.deviceid = newCreds.deviceid;
|
credentials.deviceid = newCreds.deviceid;
|
||||||
}
|
}
|
||||||
if (newCreds.pushkey == "") {
|
if (newCreds.pushkey === "") {
|
||||||
delete credentials.pushkey;
|
delete credentials.pushkey;
|
||||||
} else {
|
} else {
|
||||||
credentials.pushkey = newCreds.pushkey||credentials.pushkey;
|
credentials.pushkey = newCreds.pushkey||credentials.pushkey;
|
||||||
@ -107,4 +108,5 @@ RED.httpAdmin.post('/pushover/:id',function(req,res) {
|
|||||||
RED.nodes.addCredentials(req.params.id,credentials);
|
RED.nodes.addCredentials(req.params.id,credentials);
|
||||||
res.send(200);
|
res.send(200);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user