first version of a cloud storage read node
This commit is contained in:
@ -1,25 +1,42 @@
|
||||
const _admin = require('firebase-admin')
|
||||
const {Storage} = require('@google-cloud/storage');
|
||||
|
||||
|
||||
let init = false
|
||||
let s
|
||||
|
||||
module.exports = function(RED) {
|
||||
function FirebaseConfigNode(n) {
|
||||
RED.nodes.createNode(this,n);
|
||||
//------------------------------
|
||||
this.cred = n.cred
|
||||
this.dburl = n.dburl
|
||||
this.sturl = n.sturl
|
||||
this.bucket = n.bucket
|
||||
//------------------------------
|
||||
this.admin = _admin
|
||||
this.storage = s
|
||||
if(!init){
|
||||
console.log('setting admin....')
|
||||
init = true
|
||||
this.credentials = JSON.parse(this.cred);
|
||||
this.dburl = this.dburl
|
||||
this.sturl = this.sturl
|
||||
let credobj = _admin.credential.cert(this.credentials)
|
||||
//console.dir(credobj)
|
||||
//process.env.GOOGLE_APPLICATION_CREDENTIALS = 'creds.json'
|
||||
init = true
|
||||
|
||||
console.log('*** parsed firebase credentials: '+this.credentials.type+', project-id: '+this.credentials.project_id)
|
||||
_admin.initializeApp({
|
||||
credential: _admin.credential.cert(this.credentials),
|
||||
databaseURL: this.dburl,
|
||||
storageBucket: this.sturl
|
||||
credential: credobj,
|
||||
databaseURL: this.dburl
|
||||
});
|
||||
console.log('setting storage....')
|
||||
|
||||
s = new Storage({
|
||||
//projectId: 'something-2e584',
|
||||
//email: 'firebase-adminsdk-d1xiy@something-2e584.iam.gserviceaccount.com',
|
||||
credentials: this.credentials
|
||||
})
|
||||
|
||||
//s = new Storage()
|
||||
}
|
||||
}
|
||||
RED.nodes.registerType("firebase-config", FirebaseConfigNode);
|
||||
|
||||
Reference in New Issue
Block a user