added environment variables to control updates of flows
This commit is contained in:
@ -19,6 +19,7 @@ module.exports = function(RED) {
|
|||||||
console.log('flow-to-rtdb path='+this.path+', flowId='+this.flowId)
|
console.log('flow-to-rtdb path='+this.path+', flowId='+this.flowId)
|
||||||
|
|
||||||
runtime.flows.getFlow({id: this.flowId}).then((flow)=>{
|
runtime.flows.getFlow({id: this.flowId}).then((flow)=>{
|
||||||
|
flow.updated_at = Date.now()
|
||||||
this.admin.database().ref(this.path).set(flow).then((res)=>{
|
this.admin.database().ref(this.path).set(flow).then((res)=>{
|
||||||
console.log('firebase set result '+res)
|
console.log('firebase set result '+res)
|
||||||
console.dir(res)
|
console.dir(res)
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "node-red-contrib-firebase-admin",
|
"name": "node-red-contrib-firebase-admin",
|
||||||
"version": "1.0.4",
|
"version": "1.0.5",
|
||||||
"description": "A node-red module that wraps the server-side admin SDK of firebase, firestore, et.c.",
|
"description": "A node-red module that wraps the server-side admin SDK of firebase, firestore, et.c.",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@ -7,6 +7,7 @@
|
|||||||
name: {value:""},
|
name: {value:""},
|
||||||
flowId: {value:""},
|
flowId: {value:""},
|
||||||
path: {value:""},
|
path: {value:""},
|
||||||
|
env_var: {value:""},
|
||||||
cred: {value: "", type: 'firebase-config'}
|
cred: {value: "", type: 'firebase-config'}
|
||||||
},
|
},
|
||||||
inputs:1,
|
inputs:1,
|
||||||
@ -45,6 +46,11 @@
|
|||||||
<input type="text" id="node-input-path" placeholder="Path">
|
<input type="text" id="node-input-path" placeholder="Path">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="form-row">
|
||||||
|
<label for="node-input-env_var"><i class="icon-tag"></i> Environment variable to allow update</label>
|
||||||
|
<input type="text" id="node-input-env_var" placeholder="Env var">
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="form-row">
|
<div class="form-row">
|
||||||
<label for="node-input-cred"><i class="icon-tag"></i> Credentials</label>
|
<label for="node-input-cred"><i class="icon-tag"></i> Credentials</label>
|
||||||
<input type="text" id="node-input-cred" placeholder="Credentials">
|
<input type="text" id="node-input-cred" placeholder="Credentials">
|
||||||
|
|||||||
@ -10,10 +10,20 @@ module.exports = function(RED) {
|
|||||||
const cb = (res)=>{
|
const cb = (res)=>{
|
||||||
//console.log('firebase get result '+res)
|
//console.log('firebase get result '+res)
|
||||||
//console.dir(res)
|
//console.dir(res)
|
||||||
let val = res.val()
|
if(config.env_var && process.env[config.env_var]){
|
||||||
runtime.flows.updateFlow({id: val.id, flow: val})
|
let val = res.val()
|
||||||
//console.log('val='+val)
|
runtime.flows.getFlow({id: val.id}).then((flow)=>{
|
||||||
node.send({payload:val})
|
console.log('rtdb-to-flow old flow updated_at = '+flow.updated_at+' new flow updated_at = '+val.updated_at)
|
||||||
|
if(!flow.updated_at || val.updated_at > flow.updated_at){
|
||||||
|
console.log('updating flow...')
|
||||||
|
runtime.flows.updateFlow({id: val.id, flow: val})
|
||||||
|
}
|
||||||
|
//console.log('val='+val)
|
||||||
|
node.send({payload:val})
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
console.log('skipping flow update because environment variable '+config.env_var+' was either not defined or not set to true')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let setUpListener = (path)=>{
|
let setUpListener = (path)=>{
|
||||||
|
|||||||
Reference in New Issue
Block a user