fix(core.gbapp): Instance loading fix and external url for images.

This commit is contained in:
Rodrigo Rodriguez 2020-09-19 21:57:00 -03:00
parent a8822d9305
commit aa976aeb8c
6 changed files with 76 additions and 12 deletions

View file

@ -329,3 +329,26 @@ export class GuaribasException extends Model<GuaribasException> {
@UpdatedAt
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;
}

View file

@ -392,7 +392,9 @@ export class GBConversationalService {
case State.InEmbedAddressBegin:
if (c === ']') {
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 sleep(5000);
currentEmbedUrl = '';
@ -437,7 +439,9 @@ export class GBConversationalService {
case State.InImageAddressBody:
if (c === ')') {
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);
currentCaption = '';
await sleep(4500);

View file

@ -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.
*/
@ -323,7 +333,11 @@ STORAGE_SYNC=true
options.where = { botId: fullInstance.botId };
let instance = await GuaribasInstance.findOne(options);
// tslint:disable-next-line:prefer-object-spread
if (instance) {
instance = Object.assign(instance, fullInstance);
} else {
instance = Object.assign(new GuaribasInstance(), fullInstance);
}
try {
instance.params = JSON.stringify(JSON.parse(instance.params));
} catch (err) {

View file

@ -250,7 +250,7 @@ export class GBDeployer implements IGBDeployer {
public async deployBotFromLocalPath(localPath: string, publicAddress: string): Promise<void> {
const packageName = Path.basename(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> {

View file

@ -36,7 +36,7 @@
'use strict';
import { IGBCoreService, IGBInstance } from 'botlib';
import { IGBCoreService, IGBInstance, GBMinInstance } from 'botlib';
import fs = require('fs');
import urlJoin = require('url-join');
import { GuaribasInstance } from '../models/GBModel';
@ -58,10 +58,29 @@ export class GBImporter {
if (botId === undefined) {
botId = settingsJson.botId;
}
let instance: IGBInstance;
if (botId === undefined) {
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) {
console.log(`Null BotId after load instance with botId: ${botId}.`);
@ -76,9 +95,12 @@ export class GBImporter {
return await GuaribasInstance.create(fullSettingsJson);
}
private async createOrUpdateInstanceInternal(instance: IGBInstance,
botId: string, localPath: string, settingsJson: any) {
private async createOrUpdateInstanceInternal(
instance: IGBInstance,
botId: string,
localPath: string,
settingsJson: any
) {
let packageJson = JSON.parse(fs.readFileSync(urlJoin(localPath, 'package.json'), 'utf8'));
const servicesJson = JSON.parse(fs.readFileSync(urlJoin(localPath, 'services.json'), 'utf8'));

View file

@ -483,6 +483,7 @@ export class GBMinService {
min.sandBoxMap = {};
min.packages = sysPackages;
min.appPackages = appPackages;
// TODO: min.appPackages = core.getPackagesByInstanceId(min.instance.instanceId);
// Create a hub of services available in .gbapps.