addes storage-list and some supporting logic in storage-read
This commit is contained in:
48
storage/storage-list.js
Normal file
48
storage/storage-list.js
Normal file
@ -0,0 +1,48 @@
|
||||
|
||||
|
||||
let oldpath
|
||||
|
||||
module.exports = function(RED) {
|
||||
|
||||
function FirebaseAdmin(config) {
|
||||
RED.nodes.createNode(this, config);
|
||||
var node = this;
|
||||
|
||||
|
||||
if(config.cred){
|
||||
let c = RED.nodes.getNode(config.cred)
|
||||
this.admin = c.admin
|
||||
this.storage = c.storage
|
||||
this.bucket = config.bucket || c.bucket
|
||||
this.path = config.path
|
||||
}
|
||||
this.delimiter = config.delimiter
|
||||
|
||||
//console.log('configuring storage-list to listen for messages')
|
||||
node.on('input', function(msg) {
|
||||
if(msg && msg.payload){
|
||||
let path = msg.payload.path || this.path
|
||||
let bucket = msg.payload.bucket || this.bucket
|
||||
console.log('storage-list listing files from bucket "'+bucket+'" path "'+path+'"')
|
||||
const options = {
|
||||
prefix: path
|
||||
};
|
||||
|
||||
if(this.delimiter){
|
||||
options.delimiter = this.delimiter
|
||||
}
|
||||
|
||||
// Lists files in the bucket, filtered by a prefix
|
||||
this.storage.bucket(bucket).getFiles(options).then((files)=>{
|
||||
console.log('got file listing')
|
||||
//console.dir(files[0])
|
||||
let f = files[0].filter((e)=>{ return e.name[e.name.length-1] !== '/' })
|
||||
node.send({payload: {files: f}})
|
||||
})
|
||||
}
|
||||
}.bind(this));
|
||||
|
||||
|
||||
}
|
||||
RED.nodes.registerType("storage-list", FirebaseAdmin);
|
||||
}
|
||||
Reference in New Issue
Block a user