@@ -7,7 +7,6 @@ import { Config } from "./Config";
77import { WebSocketClient , NoderedUtil , Base } from "openflow-api" ;
88import * as nodered from "node-red" ;
99import { FileSystemCache } from "openflow-api" ;
10- const backupStore = new FileSystemCache ( path . join ( Config . logpath , '.cache' ) ) ;
1110export class noderednpmrc {
1211 public _id : string ;
1312 public _type : string = "npmrc" ;
@@ -19,6 +18,7 @@ export class noderednpmrc {
1918// tslint:disable-next-line: class-name
2019export class noderedcontribopenflowstorage {
2120
21+ private backupStore : FileSystemCache = null ;
2222 private socket : WebSocketClient = null ;
2323 private _logger : winston . Logger ;
2424 private settings : nodered_settings = null ;
@@ -37,6 +37,7 @@ export class noderedcontribopenflowstorage {
3737 this . RED = nodered ;
3838 this . _logger = logger ;
3939 this . socket = socket ;
40+ this . backupStore = new FileSystemCache ( path . join ( Config . logpath , '.cache-' + Config . nodered_id ) ) ;
4041 this . getFlows = ( this . _getFlows . bind ( this ) ) ;
4142 this . saveFlows = ( this . _saveFlows . bind ( this ) ) ;
4243 this . getCredentials = ( this . _getCredentials . bind ( this ) ) ;
@@ -371,21 +372,21 @@ export class noderedcontribopenflowstorage {
371372 }
372373 const filename : string = Config . nodered_id + "_flows.json" ;
373374 if ( result . length == 0 ) {
374- const json = await backupStore . get < string > ( filename , null ) ;
375+ const json = await this . backupStore . get < string > ( filename , null ) ;
375376 if ( ! NoderedUtil . IsNullEmpty ( json ) ) {
376377 this . _flows = JSON . parse ( json ) ;
377378 result = this . _flows ;
378379 }
379380 } else {
380- await backupStore . set ( filename , JSON . stringify ( result ) ) ;
381+ await this . backupStore . set ( filename , JSON . stringify ( result ) ) ;
381382 }
382383 return result ;
383384 }
384385 public async _saveFlows ( flows : any [ ] ) : Promise < void > {
385386 try {
386387 this . _logger . silly ( "noderedcontribopenflowstorage::_saveFlows" ) ;
387388 const filename : string = Config . nodered_id + "_flows.json" ;
388- await backupStore . set ( filename , JSON . stringify ( flows ) ) ;
389+ await this . backupStore . set ( filename , JSON . stringify ( flows ) ) ;
389390 if ( WebSocketClient . instance . isConnected ( ) ) {
390391 this . last_reload = new Date ( ) ;
391392 var result = await NoderedUtil . Query ( "nodered" , { _type : "flow" , nodered_id : Config . nodered_id } , null , null , 1 , 0 , null ) ;
@@ -433,22 +434,22 @@ export class noderedcontribopenflowstorage {
433434 }
434435 const filename : string = Config . nodered_id + "_credentials" ;
435436 if ( cred . length == 0 ) {
436- let json = await backupStore . get < string > ( filename , null ) ;
437+ let json = await this . backupStore . get < string > ( filename , null ) ;
437438 if ( ! NoderedUtil . IsNullEmpty ( json ) ) {
438439 json = noderedcontribopenflowstorage . decrypt ( json ) ;
439440 this . _credentials = JSON . parse ( json ) ;
440441 cred = this . _credentials ;
441442 }
442443 } else {
443- await backupStore . set ( filename , noderedcontribopenflowstorage . encrypt ( JSON . stringify ( cred ) ) ) ;
444+ await this . backupStore . set ( filename , noderedcontribopenflowstorage . encrypt ( JSON . stringify ( cred ) ) ) ;
444445 }
445446 return cred ;
446447 }
447448 public async _saveCredentials ( credentials : any ) : Promise < void > {
448449 try {
449450 this . _logger . silly ( "noderedcontribopenflowstorage::_saveCredentials" ) ;
450451 const filename : string = Config . nodered_id + "_credentials" ;
451- await backupStore . set ( filename , noderedcontribopenflowstorage . encrypt ( JSON . stringify ( credentials ) ) ) ;
452+ await this . backupStore . set ( filename , noderedcontribopenflowstorage . encrypt ( JSON . stringify ( credentials ) ) ) ;
452453 if ( WebSocketClient . instance . isConnected ( ) ) {
453454 this . last_reload = new Date ( ) ;
454455 var result = await NoderedUtil . Query ( "nodered" , { _type : "credential" , nodered_id : Config . nodered_id } , null , null , 1 , 0 , null ) ;
@@ -517,7 +518,7 @@ export class noderedcontribopenflowstorage {
517518 }
518519 if ( settings == null ) {
519520 settings = { } ;
520- const json = await backupStore . get < string > ( filename , null ) ;
521+ const json = await this . backupStore . get < string > ( filename , null ) ;
521522 if ( ! NoderedUtil . IsNullEmpty ( json ) ) {
522523 this . _settings = JSON . parse ( json ) ;
523524 settings = this . _settings ;
@@ -569,7 +570,7 @@ export class noderedcontribopenflowstorage {
569570 }
570571 }
571572 this . _settings = settings ;
572- await backupStore . set ( filename , JSON . stringify ( settings ) ) ;
573+ await this . backupStore . set ( filename , JSON . stringify ( settings ) ) ;
573574 }
574575 try {
575576 if ( this . firstrun ) {
@@ -722,7 +723,7 @@ export class noderedcontribopenflowstorage {
722723 try {
723724 this . _logger . silly ( "noderedcontribopenflowstorage::_saveSettings" ) ;
724725 const filename : string = Config . nodered_id + "_settings" ;
725- await backupStore . set ( filename , JSON . stringify ( settings ) ) ;
726+ await this . backupStore . set ( filename , JSON . stringify ( settings ) ) ;
726727 if ( WebSocketClient . instance . isConnected ( ) ) {
727728 this . last_reload = new Date ( ) ;
728729 var result = await NoderedUtil . Query ( "nodered" , { _type : "setting" , nodered_id : Config . nodered_id } , null , null , 1 , 0 , null ) ;
@@ -761,19 +762,19 @@ export class noderedcontribopenflowstorage {
761762 }
762763 const filename : string = Config . nodered_id + "_sessions" ;
763764 if ( item == null || item . length == 0 ) {
764- const json = await backupStore . get < string > ( filename , null ) ;
765+ const json = await this . backupStore . get < string > ( filename , null ) ;
765766 if ( ! NoderedUtil . IsNullEmpty ( json ) ) {
766767 item = JSON . parse ( json ) ;
767768 }
768769 } else {
769- await backupStore . set ( filename , JSON . stringify ( item ) ) ;
770+ await this . backupStore . set ( filename , JSON . stringify ( item ) ) ;
770771 }
771772 return item ;
772773 }
773774 public async _saveSessions ( sessions : any [ ] ) : Promise < void > {
774775 try {
775776 const filename : string = Config . nodered_id + "_sessions" ;
776- await backupStore . set ( filename , JSON . stringify ( sessions ) ) ;
777+ await this . backupStore . set ( filename , JSON . stringify ( sessions ) ) ;
777778 if ( WebSocketClient . instance . isConnected ( ) ) {
778779 this . last_reload = new Date ( ) ;
779780 var result = await NoderedUtil . Query ( "nodered" , { _type : "session" , nodered_id : Config . nodered_id } , null , null , 1 , 0 , null ) ;
0 commit comments