adding guard for other components already initalized firebase-admin

This commit is contained in:
Peter Svensson
2019-07-16 12:30:14 +02:00
parent 6ed3d21a4f
commit 6ba94648e0
2 changed files with 6 additions and 5 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "node-red-contrib-firebase-admin", "name": "node-red-contrib-firebase-admin",
"version": "1.1.9", "version": "1.1.10",
"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": {

View File

@ -1,5 +1,5 @@
let storage
module.exports = function(RED) { module.exports = function(RED) {
function FirebaseAdmin(config) { function FirebaseAdmin(config) {
@ -11,6 +11,7 @@ module.exports = function(RED) {
let c = RED.nodes.getNode(config.cred) let c = RED.nodes.getNode(config.cred)
this.admin = c.admin this.admin = c.admin
this.storage = c.storage this.storage = c.storage
storage = this.storage
this.bucket = config.bucket || c.bucket this.bucket = config.bucket || c.bucket
this.path = config.path this.path = config.path
console.log('storage-read set this.storage') console.log('storage-read set this.storage')
@ -21,7 +22,7 @@ module.exports = function(RED) {
if(msg && msg.payload){ if(msg && msg.payload){
let path = msg.payload.path || msg.path || this.path let path = msg.payload.path || msg.path || this.path
let bucket = msg.payload.bucket || msg.bucket || this.bucket let bucket = msg.payload.bucket || msg.bucket || this.bucket
console.log('------------------------------ storage-read reading from bucket "'+bucket+'" path "'+path+'"') console.log('------------------------------ storage-read reading from bucket "'+bucket+'" path "'+path+'" this.storage = '+this.storage+' storage = '+storage)
if(msg.payload.files && msg.payload.files.length > 0){ if(msg.payload.files && msg.payload.files.length > 0){
console.log('--reading from files') console.log('--reading from files')
let count = msg.payload.files.length let count = msg.payload.files.length
@ -48,8 +49,8 @@ module.exports = function(RED) {
} else if(msg){ } else if(msg){
console.log('* reading single file from path '+path) console.log('* reading single file from path '+path)
try{ try{
this.storage let s = this.storage || storage
.bucket(bucket) s.bucket(bucket)
.file(path).download().then((file)=>{ .file(path).download().then((file)=>{
console.log('storage-read got file') console.log('storage-read got file')
//console.dir(file) //console.dir(file)