added global firebase context settings

This commit is contained in:
Peter Svensson
2019-07-02 19:45:37 +02:00
parent 077199e320
commit ae90a7c225
4 changed files with 18 additions and 22 deletions

View File

@ -11,6 +11,15 @@ This means that the nodes can run outside of the normal security rules, in admin
The configuration needs two parameters, the first is the text of the service account credentials private key file. This can be found by going to the firebase console, then to the cogwheel icon at the top left then to project settings and then "Service Accounts". Click "Generate new private key)". The configuration needs two parameters, the first is the text of the service account credentials private key file. This can be found by going to the firebase console, then to the cogwheel icon at the top left then to project settings and then "Service Accounts". Click "Generate new private key)".
The second parameter is the database url for the database, and th url has the format of "https://myprojectname.firebaseio.com" and can also be fpund in the above place in the firebase console. The second parameter is the database url for the database, and th url has the format of "https://myprojectname.firebaseio.com" and can also be fpund in the above place in the firebase console.
After initializing, the reference to the firebase SDK is stored in the global context variable 'firebase', which can be used
in any function like this;
let fb = global.get('firebase')
fb.firestore().doc('foo/bar').get().then((ref)=>{
let d = ref.data()
node.send( {payload: {data: d}});
})
# Realtime Database (rtdb) Nodes # Realtime Database (rtdb) Nodes
## rtdb-get ## rtdb-get

View File

@ -28,6 +28,8 @@ module.exports = function(RED) {
credential: credobj, credential: credobj,
databaseURL: this.dburl databaseURL: this.dburl
}); });
let global = this.context().global
global.set('firebase', _admin)
console.log('setting storage....') console.log('setting storage....')
s = new Storage({ s = new Storage({

View File

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

@ -26,29 +26,14 @@ module.exports = function(RED) {
let path = msg.payload.path || this.path let path = msg.payload.path || this.path
let bucket = msg.payload.bucket || this.bucket let bucket = msg.payload.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.getBuckets().then((results)=>{ .bucket(bucket)
const [buckets] = results; .file(path).download().then((file)=>{
console.log('storage-read got file')
console.log('Buckets:'); //console.dir(file)
buckets.forEach(bucket => { node.send({payload:file})
console.log(bucket.name);
});
this.storage
.bucket(bucket)
.file(path).download().then((file)=>{
console.log('storage-read got file')
//console.dir(file)
node.send({payload:file})
})
}) })
} }
}.bind(this)); }.bind(this));