fix(core.gbapp): Instance loading fix and external url for images.
This commit is contained in:
parent
a8822d9305
commit
aa976aeb8c
6 changed files with 76 additions and 12 deletions
|
@ -329,3 +329,26 @@ export class GuaribasException extends Model<GuaribasException> {
|
||||||
@UpdatedAt
|
@UpdatedAt
|
||||||
public updatedAt: Date;
|
public updatedAt: Date;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Table
|
||||||
|
//tslint:disable-next-line:max-classes-per-file
|
||||||
|
export class GuaribasApplications extends Model<GuaribasApplications> {
|
||||||
|
|
||||||
|
@Column
|
||||||
|
public name: string;
|
||||||
|
|
||||||
|
@ForeignKey(() => GuaribasInstance)
|
||||||
|
@Column
|
||||||
|
public instanceId: number;
|
||||||
|
|
||||||
|
@BelongsTo(() => GuaribasInstance)
|
||||||
|
public instance: GuaribasInstance;
|
||||||
|
|
||||||
|
@Column
|
||||||
|
@CreatedAt
|
||||||
|
public createdAt: Date;
|
||||||
|
|
||||||
|
@Column
|
||||||
|
@UpdatedAt
|
||||||
|
public updatedAt: Date;
|
||||||
|
}
|
||||||
|
|
|
@ -162,7 +162,7 @@ export class GBConversationalService {
|
||||||
const waveFilename = `work/tmp${name}.pcm`;
|
const waveFilename = `work/tmp${name}.pcm`;
|
||||||
const sdk = require('microsoft-cognitiveservices-speech-sdk');
|
const sdk = require('microsoft-cognitiveservices-speech-sdk');
|
||||||
sdk.Recognizer.enableTelemetry(false);
|
sdk.Recognizer.enableTelemetry(false);
|
||||||
|
|
||||||
var audioConfig = sdk.AudioConfig.fromAudioFileOutput(waveFilename);
|
var audioConfig = sdk.AudioConfig.fromAudioFileOutput(waveFilename);
|
||||||
var speechConfig = sdk.SpeechConfig.fromSubscription(speechKey, cloudRegion);
|
var speechConfig = sdk.SpeechConfig.fromSubscription(speechKey, cloudRegion);
|
||||||
|
|
||||||
|
@ -392,7 +392,9 @@ export class GBConversationalService {
|
||||||
case State.InEmbedAddressBegin:
|
case State.InEmbedAddressBegin:
|
||||||
if (c === ']') {
|
if (c === ']') {
|
||||||
state = State.InEmbedEnd;
|
state = State.InEmbedEnd;
|
||||||
let url = urlJoin(GBServer.globals.publicAddress, currentEmbedUrl);
|
let url = currentEmbedUrl.startsWith('http')
|
||||||
|
? currentEmbedUrl
|
||||||
|
: urlJoin(GBServer.globals.publicAddress, currentEmbedUrl);
|
||||||
await this.sendFile(min, step, mobile, url, null);
|
await this.sendFile(min, step, mobile, url, null);
|
||||||
await sleep(5000);
|
await sleep(5000);
|
||||||
currentEmbedUrl = '';
|
currentEmbedUrl = '';
|
||||||
|
@ -437,7 +439,9 @@ export class GBConversationalService {
|
||||||
case State.InImageAddressBody:
|
case State.InImageAddressBody:
|
||||||
if (c === ')') {
|
if (c === ')') {
|
||||||
state = State.InText;
|
state = State.InText;
|
||||||
let url = urlJoin(GBServer.globals.publicAddress, currentImage);
|
let url = currentImage.startsWith('http')
|
||||||
|
? currentImage
|
||||||
|
: urlJoin(GBServer.globals.publicAddress, currentImage);
|
||||||
await this.sendFile(min, step, mobile, url, currentCaption);
|
await this.sendFile(min, step, mobile, url, currentCaption);
|
||||||
currentCaption = '';
|
currentCaption = '';
|
||||||
await sleep(4500);
|
await sleep(4500);
|
||||||
|
|
|
@ -224,6 +224,16 @@ export class GBCoreService implements IGBCoreService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// public async getPackagesByInstanceId(instanceId: number): Promise<IGBPackage[]> {
|
||||||
|
|
||||||
|
// const options = {
|
||||||
|
// where: {
|
||||||
|
// instanceId: instanceId
|
||||||
|
// }
|
||||||
|
// };
|
||||||
|
// return GuaribasApplications.findAll(options);
|
||||||
|
// }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads just one Bot instance by its internal Id.
|
* Loads just one Bot instance by its internal Id.
|
||||||
*/
|
*/
|
||||||
|
@ -323,7 +333,11 @@ STORAGE_SYNC=true
|
||||||
options.where = { botId: fullInstance.botId };
|
options.where = { botId: fullInstance.botId };
|
||||||
let instance = await GuaribasInstance.findOne(options);
|
let instance = await GuaribasInstance.findOne(options);
|
||||||
// tslint:disable-next-line:prefer-object-spread
|
// tslint:disable-next-line:prefer-object-spread
|
||||||
instance = Object.assign(instance, fullInstance);
|
if (instance) {
|
||||||
|
instance = Object.assign(instance, fullInstance);
|
||||||
|
} else {
|
||||||
|
instance = Object.assign(new GuaribasInstance(), fullInstance);
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
instance.params = JSON.stringify(JSON.parse(instance.params));
|
instance.params = JSON.stringify(JSON.parse(instance.params));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
|
@ -250,7 +250,7 @@ export class GBDeployer implements IGBDeployer {
|
||||||
public async deployBotFromLocalPath(localPath: string, publicAddress: string): Promise<void> {
|
public async deployBotFromLocalPath(localPath: string, publicAddress: string): Promise<void> {
|
||||||
const packageName = Path.basename(localPath);
|
const packageName = Path.basename(localPath);
|
||||||
let instance = await this.importer.importIfNotExistsBotPackage(undefined, packageName, localPath);
|
let instance = await this.importer.importIfNotExistsBotPackage(undefined, packageName, localPath);
|
||||||
this.deployBotFull(instance, publicAddress);
|
await this.deployBotFull(instance, publicAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async loadParamsFromExcel(min: GBMinInstance): Promise<any> {
|
public async loadParamsFromExcel(min: GBMinInstance): Promise<any> {
|
||||||
|
|
|
@ -36,7 +36,7 @@
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
import { IGBCoreService, IGBInstance } from 'botlib';
|
import { IGBCoreService, IGBInstance, GBMinInstance } from 'botlib';
|
||||||
import fs = require('fs');
|
import fs = require('fs');
|
||||||
import urlJoin = require('url-join');
|
import urlJoin = require('url-join');
|
||||||
import { GuaribasInstance } from '../models/GBModel';
|
import { GuaribasInstance } from '../models/GBModel';
|
||||||
|
@ -58,15 +58,34 @@ export class GBImporter {
|
||||||
if (botId === undefined) {
|
if (botId === undefined) {
|
||||||
botId = settingsJson.botId;
|
botId = settingsJson.botId;
|
||||||
}
|
}
|
||||||
|
let instance: IGBInstance;
|
||||||
if (botId === undefined) {
|
if (botId === undefined) {
|
||||||
botId = GBConfigService.get('BOT_ID');
|
botId = GBConfigService.get('BOT_ID');
|
||||||
|
instance = await this.core.loadInstanceByBotId(botId);
|
||||||
|
if (!instance) {
|
||||||
|
instance = <IGBInstance>{};
|
||||||
|
instance.adminPass = GBConfigService.get('ADMIN_PASS');
|
||||||
|
instance.botId = GBConfigService.get('BOT_ID');
|
||||||
|
instance.cloudSubscriptionId = GBConfigService.get('CLOUD_SUBSCRIPTIONID');
|
||||||
|
instance.cloudLocation = GBConfigService.get('CLOUD_LOCATION');
|
||||||
|
instance.cloudUsername = GBConfigService.get('CLOUD_USERNAME');
|
||||||
|
instance.cloudPassword = GBConfigService.get('CLOUD_PASSWORD');
|
||||||
|
instance.marketplaceId = GBConfigService.get('MARKETPLACE_ID');
|
||||||
|
instance.marketplacePassword = GBConfigService.get('MARKETPLACE_SECRET');
|
||||||
|
instance.storageDialect = GBConfigService.get('STORAGE_DIALECT');
|
||||||
|
instance.storageServer = GBConfigService.get('STORAGE_SERVER');
|
||||||
|
instance.storageName = GBConfigService.get('STORAGE_NAME');
|
||||||
|
instance.storageUsername = GBConfigService.get('STORAGE_USERNAME');
|
||||||
|
instance.storagePassword = GBConfigService.get('STORAGE_PASSWORD');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
instance = await this.core.loadInstanceByBotId(botId);
|
||||||
}
|
}
|
||||||
const instance = await this.core.loadInstanceByBotId(botId);
|
|
||||||
|
|
||||||
if (instance != null && instance.botId === null) {
|
if (instance != null && instance.botId === null) {
|
||||||
console.log(`Null BotId after load instance with botId: ${botId}.`);
|
console.log(`Null BotId after load instance with botId: ${botId}.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return await this.createOrUpdateInstanceInternal(instance, botId, localPath, settingsJson);
|
return await this.createOrUpdateInstanceInternal(instance, botId, localPath, settingsJson);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,9 +95,12 @@ export class GBImporter {
|
||||||
return await GuaribasInstance.create(fullSettingsJson);
|
return await GuaribasInstance.create(fullSettingsJson);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async createOrUpdateInstanceInternal(
|
||||||
private async createOrUpdateInstanceInternal(instance: IGBInstance,
|
instance: IGBInstance,
|
||||||
botId: string, localPath: string, settingsJson: any) {
|
botId: string,
|
||||||
|
localPath: string,
|
||||||
|
settingsJson: any
|
||||||
|
) {
|
||||||
let packageJson = JSON.parse(fs.readFileSync(urlJoin(localPath, 'package.json'), 'utf8'));
|
let packageJson = JSON.parse(fs.readFileSync(urlJoin(localPath, 'package.json'), 'utf8'));
|
||||||
const servicesJson = JSON.parse(fs.readFileSync(urlJoin(localPath, 'services.json'), 'utf8'));
|
const servicesJson = JSON.parse(fs.readFileSync(urlJoin(localPath, 'services.json'), 'utf8'));
|
||||||
|
|
||||||
|
|
|
@ -482,7 +482,8 @@ export class GBMinService {
|
||||||
min.scriptMap = {};
|
min.scriptMap = {};
|
||||||
min.sandBoxMap = {};
|
min.sandBoxMap = {};
|
||||||
min.packages = sysPackages;
|
min.packages = sysPackages;
|
||||||
min.appPackages = appPackages;
|
min.appPackages = appPackages;
|
||||||
|
// TODO: min.appPackages = core.getPackagesByInstanceId(min.instance.instanceId);
|
||||||
|
|
||||||
// Create a hub of services available in .gbapps.
|
// Create a hub of services available in .gbapps.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue