From eee48ee52099c54e18194bc16eaae7ec493e6c4b Mon Sep 17 00:00:00 2001 From: "Rodrigo Rodriguez (pragmatismo.io)" Date: Thu, 11 Oct 2018 10:53:22 -0300 Subject: [PATCH] Storage sync logic and some refactoring. --- deploy/default.gbui/src/GBUIApp.js | 30 +++++++++++++++--------------- src/app.ts | 16 ++++++++++------ 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/deploy/default.gbui/src/GBUIApp.js b/deploy/default.gbui/src/GBUIApp.js index 45901fc4..57768a39 100644 --- a/deploy/default.gbui/src/GBUIApp.js +++ b/deploy/default.gbui/src/GBUIApp.js @@ -52,7 +52,7 @@ class GBUIApp extends React.Component { super(); this.state = { - botConnection: null, + line: null, instance: null, token: null, instanceClient: null @@ -63,7 +63,7 @@ class GBUIApp extends React.Component { sendToken(token) { setTimeout(() => { - window.botConnection + window.line .postActivity({ type: "event", name: "updateToken", @@ -81,7 +81,7 @@ class GBUIApp extends React.Component { } send(command) { - window.botConnection + window.line .postActivity({ type: "event", name: command, @@ -98,7 +98,7 @@ class GBUIApp extends React.Component { } postEvent(name, value) { - window.botConnection.postActivity({ + window.line.postActivity({ type: "event", value: value, from: this.getUser(), @@ -107,7 +107,7 @@ class GBUIApp extends React.Component { } postMessage(value) { - window.botConnection.postActivity({ + window.line.postActivity({ type: "message", text: value, from: this.getUser() @@ -175,14 +175,14 @@ class GBUIApp extends React.Component { let _this_ = this; window["botchatDebug"] = true; - const botConnection = new DirectLine({ + const line = new DirectLine({ secret: this.state.instanceClient.secret }); - botConnection.connectionStatus$.subscribe(connectionStatus => { + line.connectionStatus$.subscribe(connectionStatus => { if (connectionStatus === ConnectionStatus.Online) { - _this_.setState({ botConnection: botConnection }); - botConnection.postActivity({ + _this_.setState({ line: line }); + line.postActivity({ type: "event", value: "startGB", from: this.getUser(), @@ -191,10 +191,10 @@ class GBUIApp extends React.Component { } }); - window.botConnection = botConnection; + window.line = line; this.postEvent("startGB", true); - botConnection.activity$ + line.activity$ .filter( activity => activity.type === "event" && activity.name === "loadInstance" @@ -204,7 +204,7 @@ class GBUIApp extends React.Component { _this_.authenticate() }); - botConnection.activity$ + line.activity$ .filter(activity => activity.type === "event" && activity.name === "stop") .subscribe(activity => { if (_this_.player) { @@ -212,7 +212,7 @@ class GBUIApp extends React.Component { } }); - botConnection.activity$ + line.activity$ .filter(activity => activity.type === "event" && activity.name === "play") .subscribe(activity => { _this_.setState({ playerType: activity.value.playerType }); @@ -312,7 +312,7 @@ class GBUIApp extends React.Component { ); - if (this.state.botConnection && this.state.instance) { + if (this.state.line && this.state.instance) { let token = this.state.instanceClient.speechToken; gbCss = ; @@ -342,7 +342,7 @@ class GBUIApp extends React.Component { this.chat = chat; }} locale={'pt-br'} - botConnection={this.state.botConnection} + line={this.state.line} user={this.getUser()} bot={{ id: "bot@gb", name: "Bot" }} speechOptions={speechOptions} diff --git a/src/app.ts b/src/app.ts index 350aad45..ba7e804d 100644 --- a/src/app.ts +++ b/src/app.ts @@ -145,17 +145,21 @@ export class GBServer { try { instances = await core.loadInstances(); } catch (error) { + // Check if storage is empty and needs formatting. let isInvalidObject = error.parent.number == 208 || error.parent.errno == 1; // MSSQL or SQLITE. - if ( - isInvalidObject && - GBConfigService.get("STORAGE_SYNC") !== "true" - ) { - throw `Operating storage is out of sync or there is a storage connection error. Try setting STORAGE_SYNC to true in .env file. Error: ${ + + if (isInvalidObject) { + if (GBConfigService.get("STORAGE_SYNC") != "true") { + throw `Operating storage is out of sync or there is a storage connection error. Try setting STORAGE_SYNC to true in .env file. Error: ${ error.message - }.`; + }.`; + } + else{ + logger.info(`Storage is empty. After collecting storage structure from all .gbapps it will get synced.`); + } } else { throw `Cannot connect to operating storage: ${error.message}.`; }