mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
Tidy up pushbullet (no fixes)
remove old migration code)
This commit is contained in:
parent
e5f41880c3
commit
4884550215
@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
<!-- PUSHBULLET CONFIG -->
|
<!-- PUSHBULLET CONFIG -->
|
||||||
|
|
||||||
<script type="text/x-red" data-template-name="pushbullet-config">
|
<script type="text/html" data-template-name="pushbullet-config">
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
|
<label for="node-config-input-name"><i class="fa fa-tag"></i> Name</label>
|
||||||
<input type="text" id="node-config-input-name" placeholder="Name">
|
<input type="text" id="node-config-input-name" placeholder="Name">
|
||||||
@ -30,7 +30,7 @@
|
|||||||
|
|
||||||
<!-- PUSHBULLET OUT -->
|
<!-- PUSHBULLET OUT -->
|
||||||
|
|
||||||
<script type="text/x-red" data-template-name="pushbullet">
|
<script type="text/html" data-template-name="pushbullet">
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-config"><i class="fa fa-user"></i> Config</label>
|
<label for="node-input-config"><i class="fa fa-user"></i> Config</label>
|
||||||
<input type="text" id="node-input-config">
|
<input type="text" id="node-input-config">
|
||||||
@ -72,12 +72,9 @@
|
|||||||
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
|
||||||
<input type="text" id="node-input-name" placeholder="Name">
|
<input type="text" id="node-input-name" placeholder="Name">
|
||||||
</div>
|
</div>
|
||||||
<div class="form-tips" id="pushbullet-migration-info" style="display: none;">
|
|
||||||
<p><i class="fa fa-random"></i> Configuration node has been migrated, please click Ok and then re-deploy flow to save settings.</p>
|
|
||||||
</div>
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script type="text/x-red" data-help-name="pushbullet">
|
<script type="text/html" data-help-name="pushbullet">
|
||||||
<p>Uses PushBullet to push <code>msg.payload</code> to a device that has the PushBullet app installed.</p>
|
<p>Uses PushBullet to push <code>msg.payload</code> to a device that has the PushBullet app installed.</p>
|
||||||
<p>Optionally uses <code>msg.topic</code> to set the title, if not already set in the properties.</p>
|
<p>Optionally uses <code>msg.topic</code> to set the title, if not already set in the properties.</p>
|
||||||
<p>Optionally uses <code>msg.pushtype</code> to set the type of the push, if not already set in the properties.</p>
|
<p>Optionally uses <code>msg.pushtype</code> to set the type of the push, if not already set in the properties.</p>
|
||||||
@ -122,7 +119,6 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
getName(this.credentials.deviceid);
|
getName(this.credentials.deviceid);
|
||||||
}
|
}
|
||||||
@ -131,7 +127,6 @@
|
|||||||
getName(data.deviceid);
|
getName(data.deviceid);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.name||this.devicename||this.title||"pushbullet";
|
return this.name||this.devicename||this.title||"pushbullet";
|
||||||
},
|
},
|
||||||
labelStyle: function() {
|
labelStyle: function() {
|
||||||
@ -139,9 +134,6 @@
|
|||||||
},
|
},
|
||||||
oneditsave: function() {
|
oneditsave: function() {
|
||||||
this.devicename = undefined;
|
this.devicename = undefined;
|
||||||
if(this.migrationData) {
|
|
||||||
$.ajax('pushbullet/'+this.id+'/migrate?save=true');
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
oneditprepare: function() {
|
oneditprepare: function() {
|
||||||
var node = this, ddConfig = $('#node-input-config'), ddDevice = $('#node-input-deviceid'), ddPushtype = $('#node-input-pushtype');
|
var node = this, ddConfig = $('#node-input-config'), ddDevice = $('#node-input-deviceid'), ddPushtype = $('#node-input-pushtype');
|
||||||
@ -181,7 +173,6 @@
|
|||||||
addCurrent = false;
|
addCurrent = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(currentDevice) {
|
if(currentDevice) {
|
||||||
if(addCurrent && currentDevice !== "_msg_") {
|
if(addCurrent && currentDevice !== "_msg_") {
|
||||||
ddDevice.append('<option value="'+currentDevice+'">'+currentDevice+'</option>');
|
ddDevice.append('<option value="'+currentDevice+'">'+currentDevice+'</option>');
|
||||||
@ -191,75 +182,13 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkMigration(cb) {
|
|
||||||
$.getJSON('pushbullet/'+node.id+'/migrate', function(data) {
|
|
||||||
var showMigration = false;
|
|
||||||
node.migrationData = data.config;
|
|
||||||
if(data.migrated) {
|
|
||||||
if(data.config) {
|
|
||||||
var configId = data.config;
|
|
||||||
var configType = 'pushbullet-config';
|
|
||||||
var configTypeDef = RED.nodes.getType(configType);
|
|
||||||
RED.nodes.add({
|
|
||||||
type: configType,
|
|
||||||
id: configId,
|
|
||||||
name: "Imported",
|
|
||||||
users: [node.id],
|
|
||||||
label: configTypeDef.label,
|
|
||||||
_def: configTypeDef,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if(node.credentials) {
|
|
||||||
if(node.credentials.pushkey) {
|
|
||||||
if(ddConfig.find('option[value="'+data.config+'"]').length === 0) {
|
|
||||||
ddConfig.append('<option value="'+data.config+'">Imported</option>');
|
|
||||||
}
|
|
||||||
ddConfig.val(data.config);
|
|
||||||
showMigration = true;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
ddConfig.val("_ADD_");
|
|
||||||
}
|
|
||||||
|
|
||||||
if(node.credentials.deviceid) {
|
|
||||||
ddDevice.append('<option value="'+node.credentials.deviceid+'">Imported</option>');
|
|
||||||
ddDevice.val(node.credentials.deviceid);
|
|
||||||
showMigration = true;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
ddDevice.val("");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(showMigration) {
|
|
||||||
ddPushtype.val("note");
|
|
||||||
node.dirty = true;
|
|
||||||
$('#pushbullet-migration-info').show();
|
|
||||||
}
|
|
||||||
if(cb) {
|
|
||||||
cb(showMigration);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
checkMigration(function(migrated) {
|
|
||||||
if(!migrated) {
|
|
||||||
ddConfig.change(function() {
|
|
||||||
if(ddConfig.val() && ddConfig.val() !== "_ADD_") {
|
|
||||||
updateDeviceList();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!-- PUSHBULLET IN -->
|
<!-- PUSHBULLET IN -->
|
||||||
|
|
||||||
<script type="text/x-red" data-template-name="pushbullet in">
|
<script type="text/html" data-template-name="pushbullet in">
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-config"><i class="fa fa-user"></i> Config</label>
|
<label for="node-input-config"><i class="fa fa-user"></i> Config</label>
|
||||||
<input type="text" id="node-input-config" placeholder="Node-RED">
|
<input type="text" id="node-input-config" placeholder="Node-RED">
|
||||||
@ -277,7 +206,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<script type="text/x-red" data-help-name="pushbullet in">
|
<script type="text/html" data-help-name="pushbullet in">
|
||||||
<p>Receives Pushbullets from all devices. Messages contain the following data:</p>
|
<p>Receives Pushbullets from all devices. Messages contain the following data:</p>
|
||||||
<p><code>msg.pushtype</code>: type of message</p>
|
<p><code>msg.pushtype</code>: type of message</p>
|
||||||
<p><code>msg.topic</code>: topic information from the push</p>
|
<p><code>msg.topic</code>: topic information from the push</p>
|
||||||
|
@ -34,23 +34,11 @@ module.exports = function(RED) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
PushbulletConfig.prototype.initialise = function() {
|
PushbulletConfig.prototype.initialise = function() {
|
||||||
if (this.initialised) {
|
if (this.initialised) { return; }
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.emitter = new EventEmitter();
|
this.emitter = new EventEmitter();
|
||||||
|
|
||||||
this.initialised = true;
|
this.initialised = true;
|
||||||
var self = this;
|
var self = this;
|
||||||
|
var apikey = this.credentials.apikey;
|
||||||
// sort migration from old node
|
|
||||||
var apikey;
|
|
||||||
if (this.n._migrate) {
|
|
||||||
apikey = this.n._apikey;
|
|
||||||
this.credentials = {apikey:apikey};
|
|
||||||
}
|
|
||||||
else if (this.credentials) {
|
|
||||||
apikey = this.credentials.apikey;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (apikey) {
|
if (apikey) {
|
||||||
try {
|
try {
|
||||||
@ -254,84 +242,23 @@ module.exports = function(RED) {
|
|||||||
this._inputNodes.push(handler);
|
this._inputNodes.push(handler);
|
||||||
};
|
};
|
||||||
|
|
||||||
function migrateOldSettings(n) {
|
|
||||||
if (n.config === undefined) {
|
|
||||||
var newid, config, apikey, deviceid, pushkeys;
|
|
||||||
|
|
||||||
try {
|
|
||||||
pushkeys = RED.settings.pushbullet || require(process.env.NODE_RED_HOME+"/../pushkey.js");
|
|
||||||
}
|
|
||||||
catch(err) { }
|
|
||||||
|
|
||||||
var cred = RED.nodes.getCredentials(n.id);
|
|
||||||
// get old apikey
|
|
||||||
if (cred && cred.hasOwnProperty("pushkey")) {
|
|
||||||
apikey = cred.pushkey;
|
|
||||||
}
|
|
||||||
else if (pushkeys) {
|
|
||||||
apikey = pushkeys.pushbullet;
|
|
||||||
}
|
|
||||||
// get old device
|
|
||||||
if (cred && cred.hasOwnProperty("deviceid")) {
|
|
||||||
deviceid = cred.deviceid;
|
|
||||||
}
|
|
||||||
else if (pushkeys) {
|
|
||||||
deviceid = pushkeys.deviceid;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (apikey) {
|
|
||||||
newid = (1+Math.random()*4294967295).toString(16);
|
|
||||||
config = new PushbulletConfig({
|
|
||||||
id: newid,
|
|
||||||
type: 'pushbullet-config',
|
|
||||||
name: n.name,
|
|
||||||
_migrate: true,
|
|
||||||
_apikey: apikey,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!(apikey || deviceid)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// override configuration properties to compatible migrated ones
|
|
||||||
n.pushtype = "note";
|
|
||||||
n.deviceid = deviceid;
|
|
||||||
return {
|
|
||||||
deviceid: deviceid,
|
|
||||||
apikey: apikey,
|
|
||||||
config: config,
|
|
||||||
id: newid
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
function PushbulletOut(n) {
|
function PushbulletOut(n) {
|
||||||
RED.nodes.createNode(this, n);
|
RED.nodes.createNode(this, n);
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
this.migrated = migrateOldSettings(n);
|
|
||||||
this.title = n.title;
|
this.title = n.title;
|
||||||
this.chan = n.chan;
|
this.chan = n.chan;
|
||||||
this.pushtype = n.pushtype;
|
this.pushtype = n.pushtype;
|
||||||
this.pusher = null;
|
this.pusher = null;
|
||||||
|
|
||||||
var configNode;
|
var configNode;
|
||||||
if (this.migrated) {
|
|
||||||
this.warn('Settings migrated from previous version of Pushbullet Node, please edit node to update settings.');
|
|
||||||
this.status({fill: 'yellow', shape: 'ring', text: 'Node migrated'});
|
|
||||||
this.deviceid = this.migrated.deviceid;
|
|
||||||
configNode = this.migrated.config;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this.status({});
|
this.status({});
|
||||||
configNode = RED.nodes.getNode(n.config);
|
configNode = RED.nodes.getNode(n.config);
|
||||||
try {
|
try {
|
||||||
this.deviceid = this.credentials.deviceid;
|
this.deviceid = this.credentials.deviceid;
|
||||||
}
|
}
|
||||||
catch(err) { }
|
catch(err) { }
|
||||||
}
|
|
||||||
|
|
||||||
if (configNode) {
|
if (configNode) {
|
||||||
configNode.initialise();
|
configNode.initialise();
|
||||||
@ -462,27 +389,6 @@ module.exports = function(RED) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
RED.httpAdmin.get('/pushbullet/:id/migrate', RED.auth.needsPermission('pushbullet.read'), function(req, res) {
|
|
||||||
var node = RED.nodes.getNode(req.params.id);
|
|
||||||
if (node && node.migrated) {
|
|
||||||
if (req.query.save) {
|
|
||||||
var promise;
|
|
||||||
if (node.migrated.apikey) {
|
|
||||||
promise = RED.nodes.addCredentials(node.migrated.id, {apikey: node.migrated.apikey});
|
|
||||||
}
|
|
||||||
if (node.migrated.deviceid) {
|
|
||||||
when(promise).then(function() {
|
|
||||||
RED.nodes.addCredentials(req.params.id, {deviceid: node.migrated.deviceid});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
res.send(JSON.stringify({migrated: true, config: node.migrated.id}));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
res.send("{}");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
RED.httpAdmin.get('/pushbullet/:id/devices', RED.auth.needsPermission('pushbullet.read'), function(req, res) {
|
RED.httpAdmin.get('/pushbullet/:id/devices', RED.auth.needsPermission('pushbullet.read'), function(req, res) {
|
||||||
var config = RED.nodes.getNode(req.params.id);
|
var config = RED.nodes.getNode(req.params.id);
|
||||||
var cred = RED.nodes.getCredentials(req.params.id);
|
var cred = RED.nodes.getCredentials(req.params.id);
|
||||||
|
Loading…
Reference in New Issue
Block a user