added on nodes for rtdb and firestore andmade nodes pass through msg objects with as little changes as possible
This commit is contained in:
@ -46,4 +46,25 @@
|
||||
|
||||
<script type="text/x-red" data-help-name="storage-list">
|
||||
<p>A node that list files from bucket path in google cloud storage</p>
|
||||
Lists the contents of files in a bucket
|
||||
<p>
|
||||
If "path" is defined in the payload, only files beginning with that path will be returned. I fomitted, the root level of the bucket is listed.
|
||||
A path can also be deep likes this; "foo/bar/baz". "delimiter" is the charatcer used to delimit directory levels, "/" by default.
|
||||
<p>
|
||||
input:
|
||||
|
||||
{
|
||||
"payload": {
|
||||
"bucket": "xyzzyz123.appspot.com", // optional
|
||||
"path": "directory1", // optional
|
||||
"delimiter": "/" // optional
|
||||
}
|
||||
}
|
||||
<p>
|
||||
output: An array of google cloud-storage File objects. If you take this output and send it to a function which outputs a payload like this;
|
||||
|
||||
{"files": array_of_File_obejcts}
|
||||
<p>
|
||||
The storage-read module will read all file contents and output an object of filename keyed Buffer objects instead of the normal one.
|
||||
|
||||
</script>
|
||||
@ -1,7 +1,5 @@
|
||||
|
||||
|
||||
let oldpath
|
||||
|
||||
module.exports = function(RED) {
|
||||
|
||||
function FirebaseAdmin(config) {
|
||||
@ -37,7 +35,8 @@ module.exports = function(RED) {
|
||||
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}})
|
||||
msg.payload = {files: f}
|
||||
node.send(msg)
|
||||
})
|
||||
}
|
||||
}.bind(this));
|
||||
|
||||
@ -40,4 +40,19 @@
|
||||
|
||||
<script type="text/x-red" data-help-name="storage-read">
|
||||
<p>A node that read files from bucket path in google cloud storage</p>
|
||||
Read file data from a file at a given path under a given cloud storage bucket. The default bucket to be used can be set in the general firebase SDK settings.
|
||||
If the payload defines an optional bucket property, it will override the default bucket settings.
|
||||
<p>
|
||||
|
||||
input:
|
||||
|
||||
{
|
||||
"payload": {
|
||||
"bucket": "xyzzyz123.appspot.com",
|
||||
"path": "myFile.txt"
|
||||
}
|
||||
}
|
||||
<p>
|
||||
output: Buffer object containing the binary file contents. Can easily be converted to a string by calling toString() on the Buffer.
|
||||
|
||||
</script>
|
||||
@ -1,7 +1,5 @@
|
||||
|
||||
|
||||
let oldpath
|
||||
|
||||
module.exports = function(RED) {
|
||||
|
||||
function FirebaseAdmin(config) {
|
||||
@ -20,8 +18,8 @@ module.exports = function(RED) {
|
||||
//console.log('configuring storage-read 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
|
||||
let path = msg.payload.path || msg.path || this.path
|
||||
let bucket = msg.payload.bucket || msg.bucket || this.bucket
|
||||
console.log('------------------------------ storage-read reading from bucket "'+bucket+'" path "'+path+'"')
|
||||
if(msg.payload.files && msg.payload.files.length > 0){
|
||||
console.log('--reading from files')
|
||||
@ -36,12 +34,13 @@ module.exports = function(RED) {
|
||||
console.log('storage-read got file '+file.name)
|
||||
rv[file.name] = content
|
||||
if(--count === 0){
|
||||
console.log('all files done, sending..')
|
||||
for(let x in rv){
|
||||
console.log(x)
|
||||
}
|
||||
node.send({payload:rv})
|
||||
msg.payload = rv
|
||||
node.send(msg)
|
||||
}
|
||||
}, (fail)=>{
|
||||
console.log('storage-read could not find file '+path)
|
||||
msg.payload = undefined
|
||||
node.send(msg)
|
||||
})
|
||||
})(_file)
|
||||
})
|
||||
@ -52,8 +51,12 @@ module.exports = function(RED) {
|
||||
.file(path).download().then((file)=>{
|
||||
console.log('storage-read got file')
|
||||
//console.dir(file)
|
||||
node.send({payload:file})
|
||||
|
||||
msg.payload = file
|
||||
node.send(msg)
|
||||
}, (fail)=>{
|
||||
console.log('storage-read could not find single file '+path)
|
||||
msg.payload = undefined
|
||||
node.send(msg)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -40,4 +40,26 @@
|
||||
|
||||
<script type="text/x-red" data-help-name="storage-write">
|
||||
<p>A node that read files from bucket path in google cloud storage</p>
|
||||
Writes the content of JavaScript Buffer object to a file path in a storage bucket.
|
||||
<p>
|
||||
input:
|
||||
|
||||
{
|
||||
"payload": {
|
||||
"bucket": "abc.appspot.com", // optional, is otherwise set as node config
|
||||
"path": "foo/bar/baz.json", // optional, see above
|
||||
"contents": <Buffer obj>,
|
||||
"contentType": "application/json" }, // optional
|
||||
"metadata": { "very":"interesting"}, // optional
|
||||
"public": true, // optional
|
||||
"private": false // optional
|
||||
}
|
||||
}
|
||||
<p>
|
||||
output:
|
||||
|
||||
{
|
||||
"payload": {"success": true, "filename": "foo/bar.txt"} // ot false if an error occurred
|
||||
}
|
||||
|
||||
</script>
|
||||
@ -17,27 +17,27 @@ module.exports = function(RED) {
|
||||
//console.log('configuring storage-write 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
|
||||
let contents = msg.payload.contents
|
||||
let path = msg.payload.path || msg.path|| this.path
|
||||
let bucket = msg.payload.bucket || msg.bucket || this.bucket
|
||||
let contents = msg.payload.contents || msg.payload
|
||||
let options ={
|
||||
contentType: msg.payload.contentType || 'auto',
|
||||
metadata: msg.payload.metadata || {},
|
||||
private: msg.payload.private || true,
|
||||
public: msg.payload.public || true,
|
||||
contentType: msg.payload.contentType || msg.contentType || 'auto',
|
||||
metadata: msg.payload.metadata || msg.metadata || {},
|
||||
private: msg.payload.private || msg.private || true,
|
||||
public: msg.payload.public || msg.public || true,
|
||||
}
|
||||
console.log('storage-write writing file to bucket "'+bucket+'" path "'+path+'" contents is of type '+(typeof contents))
|
||||
console.dir(contents)
|
||||
const myBucket = this.storage.bucket(bucket);
|
||||
const file = myBucket.file(path);
|
||||
file.save(contents, options, function(err) {
|
||||
if (!err) {
|
||||
// File written successfully.
|
||||
node.send({payload:{success:true, filename: path}})
|
||||
msg.payload={success:true, filename: path}
|
||||
} else {
|
||||
console.log('cloud storage write error: '+err)
|
||||
node.send({payload:{success:false, filename: path}})
|
||||
msg.payload ={success:false, filename: path}
|
||||
}
|
||||
node.send(msg)
|
||||
});
|
||||
}
|
||||
}.bind(this));
|
||||
|
||||
Reference in New Issue
Block a user