fix(all): TRUE multicloud.
This commit is contained in:
parent
1765e8f50e
commit
c2bdbbe140
7 changed files with 79 additions and 60 deletions
|
@ -285,7 +285,7 @@ export class GBVMService extends GBService {
|
||||||
// Loads storage custom connections.
|
// Loads storage custom connections.
|
||||||
const path = DialogKeywords.getGBAIPath(min.botId, null);
|
const path = DialogKeywords.getGBAIPath(min.botId, null);
|
||||||
const filePath = Path.join('work', path, 'connections.json');
|
const filePath = Path.join('work', path, 'connections.json');
|
||||||
let connections = null;
|
let connections = [];
|
||||||
if (Fs.existsSync(filePath)) {
|
if (Fs.existsSync(filePath)) {
|
||||||
connections = JSON.parse(Fs.readFileSync(filePath, 'utf8'));
|
connections = JSON.parse(Fs.readFileSync(filePath, 'utf8'));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1745,20 +1745,23 @@ export class SystemKeywords {
|
||||||
|
|
||||||
private flattenJSON(obj, res = {}, separator = '_', parent = null) {
|
private flattenJSON(obj, res = {}, separator = '_', parent = null) {
|
||||||
for (let key in obj) {
|
for (let key in obj) {
|
||||||
if (typeof obj[key] === 'function') {
|
if (!obj.hasOwnProperty(key) || typeof obj[key] === 'function') {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (typeof obj[key] !== 'object' || obj[key] instanceof Date) {
|
if (typeof obj[key] !== 'object' || obj[key] instanceof Date) {
|
||||||
// If not defined already add the flattened field.
|
// If not defined already, add the flattened field.
|
||||||
|
|
||||||
const newKey = `${parent ? parent + separator : ''}${key}`;
|
const newKey = `${parent ? parent + separator : ''}${key}`;
|
||||||
if (!res[newKey]) {
|
if (!res.hasOwnProperty(newKey)) {
|
||||||
res[newKey] = obj[key];
|
res[newKey] = obj[key];
|
||||||
} else {
|
} else {
|
||||||
GBLog.verbose(`Ignoring duplicated field in flatten operation to storage: ${key}.`);
|
GBLog.verbose(`Ignoring duplicated field in flatten operation to storage: ${key}.`);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
obj[key] = this.flattenJSON(obj[key], res, separator, `${parent ? parent + separator : ''}${key}`);
|
// Create a temporary reference to the nested object to prevent memory leaks.
|
||||||
|
const tempObj = obj[key];
|
||||||
|
this.flattenJSON(tempObj, res, separator, `${parent ? parent + separator : ''}${key}`);
|
||||||
|
// Clear the reference to avoid holding unnecessary objects in memory.
|
||||||
|
obj[key] = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
|
|
|
@ -81,6 +81,9 @@ export class GBConfigService {
|
||||||
|
|
||||||
if (!value) {
|
if (!value) {
|
||||||
switch (key) {
|
switch (key) {
|
||||||
|
case 'PORT':
|
||||||
|
value = this.getServerPort();
|
||||||
|
break;
|
||||||
case 'STORAGE_NAME':
|
case 'STORAGE_NAME':
|
||||||
value = null;
|
value = null;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -872,7 +872,7 @@ ENDPOINT_UPDATE=true
|
||||||
Fs.cpSync(Path.join(base, `default.gbdialog`), Path.join(gbaiPath, `default.gbdialog`), {
|
Fs.cpSync(Path.join(base, `default.gbdialog`), Path.join(gbaiPath, `default.gbdialog`), {
|
||||||
errorOnExist: false,
|
errorOnExist: false,
|
||||||
force: true,
|
force: true,
|
||||||
recursive: true
|
recursive: true,
|
||||||
});
|
});
|
||||||
Fs.cpSync(Path.join(base, `default.gbdrive`), Path.join(gbaiPath, `default.gbdrive`), {
|
Fs.cpSync(Path.join(base, `default.gbdrive`), Path.join(gbaiPath, `default.gbdrive`), {
|
||||||
errorOnExist: false,
|
errorOnExist: false,
|
||||||
|
|
|
@ -422,40 +422,50 @@ export class GBDeployer implements IGBDeployer {
|
||||||
/**
|
/**
|
||||||
* Loads all para from tabular file Config.xlsx.
|
* Loads all para from tabular file Config.xlsx.
|
||||||
*/
|
*/
|
||||||
public async loadParamsFromTabular(min: GBMinInstance, path): Promise<any> {
|
|
||||||
const workbook = new Excel.Workbook();
|
|
||||||
const data = await workbook.xlsx.readFile(Path.join(path, 'Config.xlsx'));
|
|
||||||
|
|
||||||
|
public async loadParamsFromTabular(min: GBMinInstance, filePath: string): Promise<any> {
|
||||||
|
if (!Fs.existsSync(filePath)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
const ext = Path.extname(filePath).toLowerCase();
|
||||||
|
let rows: any[] = [];
|
||||||
|
|
||||||
|
const workbook = new Excel.Workbook();
|
||||||
|
|
||||||
|
if (ext === '.xlsx') {
|
||||||
|
await workbook.xlsx.readFile(filePath);
|
||||||
let worksheet: any;
|
let worksheet: any;
|
||||||
for (let t = 0; t < data.worksheets.length; t++) {
|
for (let t = 0; t < workbook.worksheets.length; t++) {
|
||||||
worksheet = data.worksheets[t];
|
worksheet = workbook.worksheets[t];
|
||||||
if (worksheet) {
|
if (worksheet) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const rows = worksheet._rows;
|
rows = worksheet.getSheetValues();
|
||||||
GBLogEx.info(min, `Processing ${rows.length} rows from Config file ${path}...`);
|
} else if (ext === '.csv') {
|
||||||
let list = [];
|
await workbook.csv.readFile(filePath);
|
||||||
|
let worksheet = workbook.worksheets[0]; // Assuming the CSV file has only one sheet
|
||||||
|
rows = worksheet.getSheetValues();
|
||||||
|
} else {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
GBLogEx.info(min, `Processing ${rows.length} rows from Config file ${filePath}...`);
|
||||||
|
|
||||||
// Skips the header lines.
|
// Skips the header lines.
|
||||||
|
|
||||||
for (let index = 0; index < 6; index++) {
|
for (let index = 0; index < 6; index++) {
|
||||||
rows.shift();
|
rows.shift();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let obj: any = {};
|
||||||
let obj = {};
|
await asyncPromise.eachSeries(rows, async (line: any) => {
|
||||||
await asyncPromise.eachSeries(rows, async line => {
|
|
||||||
|
|
||||||
if (line && line._cells[0] && line._cells[1] && line._cells[0].text) {
|
if (line && line._cells[0] && line._cells[1] && line._cells[0].text) {
|
||||||
|
|
||||||
// Extracts values from columns in the current line.
|
|
||||||
|
|
||||||
obj[line._cells[0].text] = line._cells[1].text;
|
obj[line._cells[0].text] = line._cells[1].text;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
GBLogEx.info(min, GBUtil.toYAML(list));
|
GBLogEx.info(min, GBUtil.toYAML(obj));
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -614,9 +624,12 @@ export class GBDeployer implements IGBDeployer {
|
||||||
|
|
||||||
switch (packageType) {
|
switch (packageType) {
|
||||||
case '.gbot':
|
case '.gbot':
|
||||||
|
|
||||||
|
|
||||||
// Extracts configuration information from .gbot files.
|
// Extracts configuration information from .gbot files.
|
||||||
|
|
||||||
min.instance.params = await this.loadParamsFromTabular(min, localPath);
|
min.instance.params = await this.loadParamsFromTabular(min, localPath);
|
||||||
|
if (min.instance.params.length){
|
||||||
|
|
||||||
let connections = [];
|
let connections = [];
|
||||||
|
|
||||||
|
@ -643,7 +656,7 @@ export class GBDeployer implements IGBDeployer {
|
||||||
// Updates instance object.
|
// Updates instance object.
|
||||||
|
|
||||||
await this.core.saveInstance(min.instance);
|
await this.core.saveInstance(min.instance);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '.gbkb':
|
case '.gbkb':
|
||||||
|
|
|
@ -700,7 +700,7 @@ export class GBMinService {
|
||||||
};
|
};
|
||||||
|
|
||||||
if (!GBConfigService.get('STORAGE_NAME')) {
|
if (!GBConfigService.get('STORAGE_NAME')) {
|
||||||
config['domain'] = `http://localhost:${process.env.PORT}/directline/${botId}`;
|
config['domain'] = `http://localhost:${GBConfigService.get('PORT')}/directline/${botId}`;
|
||||||
} else {
|
} else {
|
||||||
const webchatTokenContainer = await this.getWebchatToken(instance);
|
const webchatTokenContainer = await this.getWebchatToken(instance);
|
||||||
(config['conversationId'] = webchatTokenContainer.conversationId),
|
(config['conversationId'] = webchatTokenContainer.conversationId),
|
||||||
|
@ -773,7 +773,7 @@ export class GBMinService {
|
||||||
};
|
};
|
||||||
if (!GBConfigService.get('STORAGE_NAME')) {
|
if (!GBConfigService.get('STORAGE_NAME')) {
|
||||||
startRouter(GBServer.globals.server, instance.botId);
|
startRouter(GBServer.globals.server, instance.botId);
|
||||||
config['clientOptions'] = { baseUri: `http://localhost:${process.env.PORT}` };
|
config['clientOptions'] = { baseUri: `http://localhost:${GBConfigService.get('PORT')}` };
|
||||||
}
|
}
|
||||||
|
|
||||||
const adapter = new BotFrameworkAdapter(config);
|
const adapter = new BotFrameworkAdapter(config);
|
||||||
|
|
|
@ -492,7 +492,7 @@ export class ChatServices {
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
dataSource = new DataSource({
|
dataSource = new DataSource({
|
||||||
type: dialect === dialect as any,
|
type: dialect as any,
|
||||||
host: host,
|
host: host,
|
||||||
port: port,
|
port: port,
|
||||||
database: storageName,
|
database: storageName,
|
||||||
|
|
Loading…
Add table
Reference in a new issue