UNPKG

cloud-red

Version:

Serverless Node-RED for your cloud integration needs

92 lines (89 loc) 2.61 kB
var fs = require('fs'); var when = require('when'); let settings; let basePath; let flowFilePath; let storageEphemeral = { init: function(_settings) { settings = _settings; basePath = settings.basePath; flowFilePath = settings.flowFilePath; return when.promise(function(resolve, reject) { if (fs.existsSync(`${flowFilePath}`)) { console.log(`[ephemeral-storage] Flow found: ${flowFilePath}`); resolve(); } else { reject(`[ephemeral-storage] Flow not found in: ${flowFilePath}`); } }); }, getFlows: function() { return this.getData(`${flowFilePath}`); }, saveFlows: function(flow) { return when.promise(function(resolve, reject) { console.log( '[ephemeral-storage] Saving flow! - WARNING!! - This should not been invoked' ); resolve(); }); }, getCredentials: function() { return when.promise(function(resolve, reject) { console.log( '[ephemeral-storage] Get Credentials! - WARNING!! - This should not been invoked' ); resolve({}); }); }, saveCredentials: function() { return when.promise(function(resolve, reject) { console.log( '[ephemeral-storage] Saving Credentials! - WARNING!! - This should not been invoked' ); resolve(); }); }, getSettings: function() { return this.getData(`${basePath}/settings.json`); }, saveSettings: function() { return when.promise(function(resolve, reject) { console.log( '[ephemeral-storage] Saving Settings! - WARNING!! - This should not been invoked' ); resolve(); }); }, getLibraryEntry: function(type, path) { return when.promise(function(resolve, reject) { console.log( '[ephemeral-storage] Get Library Entry! - WARNING!! - This should not been invoked' ); resolve(); }); }, saveLibraryEntry: function(type, path, meta, body) { return when.promise(function(resolve, reject) { console.log( '[ephemeral-storage] Save Library Entry! - WARNING!! - This should not been invoked' ); resolve(); }); }, getData: function(entryType) { return when.promise(function(resolve, reject) { fs.readFile(entryType, 'utf8', function(err, flowContent) { if (err) { reject( `[ephemeral-storage] Error found while reading the file: ${entryType}` ); } let flowObject = JSON.parse(flowContent); // console.log(flowObject); resolve(flowObject); }); }); } }; module.exports = storageEphemeral;