refactord, tidied up, added icon for storage and a new node for writing buffers to storage files
This commit is contained in:
19
README.md
19
README.md
@ -106,8 +106,25 @@ If the payload defines an optional bucket property, it will override the default
|
||||
|
||||
input: {"payload":{"bucket": "xyzzyz123.appspot.com", "path": "myFile.txt"}}
|
||||
|
||||
output: Buffer[] containing the binary file contents
|
||||
npm publish .output: Buffer object containing the binary file contents. Can easily be converted to a string by calling toString() on the Buffer.
|
||||
|
||||
## storage-write
|
||||
Writes the content of JavaScript Buffer object to a file path in a storage bucket.
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# Auth nodes
|
||||
|
||||
|
||||
23
package.json
23
package.json
@ -21,18 +21,19 @@
|
||||
"homepage": "https://github.com/psvensson/node-red-contrib-firebase-admin#readme",
|
||||
"node-red": {
|
||||
"nodes": {
|
||||
"rtdb-set": "rtdb-set.js",
|
||||
"rtdb-push": "rtdb-push.js",
|
||||
"rtdb-get": "rtdb-get.js",
|
||||
"rtdb-query": "rtdb-query.js",
|
||||
"firestore-set": "firestore-set.js",
|
||||
"firestore-add": "firestore-add.js",
|
||||
"firestore-get": "firestore-get.js",
|
||||
"firestore-query": "firestore-query.js",
|
||||
"rtdb-set": "rtdb/rtdb-set.js",
|
||||
"rtdb-push": "rtdb/rtdb-push.js",
|
||||
"rtdb-get": "rtdb/rtdb-get.js",
|
||||
"rtdb-query": "rtdb/rtdb-query.js",
|
||||
"firestore-set": "firestore/firestore-set.js",
|
||||
"firestore-add": "firestore/firestore-add.js",
|
||||
"firestore-get": "firestore/firestore-get.js",
|
||||
"firestore-query": "firestore/firestore-query.js",
|
||||
"firebase-config": "firebase-config.js",
|
||||
"flow-to-rtdb": "flow-to-rtdb.js",
|
||||
"rtdb-to-flow": "rtdb-to-flow.js",
|
||||
"storage-read": "storage-read.js"
|
||||
"flow-to-rtdb": "rtdb/flow-to-rtdb.js",
|
||||
"rtdb-to-flow": "rtdb/rtdb-to-flow.js",
|
||||
"storage-read": "storage/storage-read.js",
|
||||
"storage-write": "storage/storage-write.js"
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
|
||||
@ -11,7 +11,7 @@
|
||||
},
|
||||
inputs:1,
|
||||
outputs:1,
|
||||
icon: "firebase-admin-icon.png",
|
||||
icon: "storage.png",
|
||||
label: function() {
|
||||
return this.name||"storage-read";
|
||||
}
|
||||
@ -17,9 +17,6 @@ module.exports = function(RED) {
|
||||
this.path = config.path
|
||||
}
|
||||
|
||||
console.log('------------------------------- rtdg-get config')
|
||||
console.dir(config)
|
||||
|
||||
//console.log('configuring storage-read to listen for messages')
|
||||
node.on('input', function(msg) {
|
||||
if(msg && msg.payload){
|
||||
43
storage/storage-write.html
Normal file
43
storage/storage-write.html
Normal file
@ -0,0 +1,43 @@
|
||||
<script type="text/javascript">
|
||||
RED.nodes.registerType('storage-write',{
|
||||
|
||||
category: 'firebase-admin',
|
||||
color: '#a6bbcf',
|
||||
defaults: {
|
||||
name: {value:""},
|
||||
path: {value:""},
|
||||
bucket: {value:""},
|
||||
cred: {value: "", type: 'firebase-config'}
|
||||
},
|
||||
inputs:1,
|
||||
outputs:0,
|
||||
icon: "storage.png",
|
||||
label: function() {
|
||||
return this.name||"storage-write";
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-template-name="storage-write">
|
||||
<div class="form-row">
|
||||
<label for="node-input-bucket"><i class="icon-tag"></i> Bucket Name</label>
|
||||
<input type="text" id="node-input-bucket" placeholder="Bucket Name">
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<label for="node-input-path"><i class="icon-tag"></i> Path</label>
|
||||
<input type="text" id="node-input-path" placeholder="Path">
|
||||
</div>
|
||||
|
||||
<div class="form-row">
|
||||
<label for="node-input-cred"><i class="icon-tag"></i> Credentials</label>
|
||||
<input type="text" id="node-input-cred" placeholder="Name">
|
||||
</div>
|
||||
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-help-name="storage-write">
|
||||
<p>A node that read files from bucket path in google cloud storage</p>
|
||||
</script>
|
||||
46
storage/storage-write.js
Normal file
46
storage/storage-write.js
Normal file
@ -0,0 +1,46 @@
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
//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 options ={
|
||||
contentType: msg.payload.contentType || 'auto',
|
||||
metadata: msg.payload.metadata || {},
|
||||
private: msg.payload.private || true,
|
||||
public: msg.payload.public || true,
|
||||
}
|
||||
console.log('storage-write writing file to bucket "'+bucket+'" path "'+path+'"')
|
||||
console.dir(msg.payload)
|
||||
const myBucket = this.storage.bucket(bucket);
|
||||
const file = myBucket.file(path);
|
||||
file.save(contents, options, function(err) {
|
||||
if (!err) {
|
||||
// File written successfully.
|
||||
} else {
|
||||
console.log('cloud storage write error: '+err)
|
||||
}
|
||||
});
|
||||
}
|
||||
}.bind(this));
|
||||
|
||||
|
||||
}
|
||||
RED.nodes.registerType("storage-write", FirebaseAdmin);
|
||||
}
|
||||
Reference in New Issue
Block a user