new(default.gbui): Load time reduced for web page display.
This commit is contained in:
parent
a0648b3d42
commit
01fa276eb0
4 changed files with 68 additions and 36 deletions
|
@ -274,17 +274,22 @@ export class GBVMService extends GBService {
|
|||
}
|
||||
|
||||
if (text) {
|
||||
text = text.replace('¨', '"');
|
||||
text = text.replace('“', '"');
|
||||
text = text.replace('”', '"');
|
||||
text = text.replace('‘', "'");
|
||||
text = text.replace('’', "'");
|
||||
text = GBVMService.normalizeQuotes(text);
|
||||
}
|
||||
resolve(text);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public static normalizeQuotes(text: any) {
|
||||
text = text.replace('¨', '"');
|
||||
text = text.replace('“', '"');
|
||||
text = text.replace('”', '"');
|
||||
text = text.replace('‘', "'");
|
||||
text = text.replace('’', "'");
|
||||
return text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts General Bots BASIC
|
||||
*
|
||||
|
@ -319,7 +324,14 @@ export class GBVMService extends GBService {
|
|||
/**
|
||||
* Executes the converted JavaScript from BASIC code inside execution context.
|
||||
*/
|
||||
public static async callVM(text: string, min: GBMinInstance, step, user:GuaribasUser, deployer: GBDeployer, debug: boolean = false) {
|
||||
public static async callVM(
|
||||
text: string,
|
||||
min: GBMinInstance,
|
||||
step,
|
||||
user: GuaribasUser,
|
||||
deployer: GBDeployer,
|
||||
debug: boolean = false
|
||||
) {
|
||||
// Creates a class DialogKeywords which is the *this* pointer
|
||||
// in BASIC.
|
||||
|
||||
|
@ -331,17 +343,18 @@ export class GBVMService extends GBService {
|
|||
GBConfigService.get('DEFAULT_CONTENT_LANGUAGE')
|
||||
);
|
||||
|
||||
// TODO: https://github.com/GeneralBots/BotServer/issues/217
|
||||
// Auto-NLP generates BASIC variables related to entities.
|
||||
|
||||
if (step && step.context.activity['originalText']) {
|
||||
const entities = await min['nerEngine'].findEntities(step.context.activity['originalText'], contentLocale);
|
||||
// if (step && step.context.activity['originalText'] && min['nerEngine']) {
|
||||
// const entities = await min['nerEngine'].findEntities(step.context.activity['originalText'], contentLocale);
|
||||
|
||||
for (let i = 0; i < entities.length; i++) {
|
||||
const v = entities[i];
|
||||
const variableName = `${v.entity}`;
|
||||
sandbox[variableName] = v.option;
|
||||
}
|
||||
}
|
||||
// for (let i = 0; i < entities.length; i++) {
|
||||
// const v = entities[i];
|
||||
// const variableName = `${v.entity}`;
|
||||
// sandbox[variableName] = v.option;
|
||||
// }
|
||||
// }
|
||||
|
||||
const botId = min.botId;
|
||||
const gbdialogPath = urlJoin(process.cwd(), 'work', `${botId}.gbai`, `${botId}.gbdialog`);
|
||||
|
|
|
@ -272,7 +272,10 @@ export class GBSSR {
|
|||
// Reads from static HTML when a bot is crawling.
|
||||
|
||||
const botId = req.originalUrl ? req.originalUrl.substr(1) : GBServer.globals.minInstances[0].botId; // TODO: Get only bot.
|
||||
const min: GBMinInstance = GBServer.globals.minInstances.filter(p => p.instance.botId === botId)[0];
|
||||
let min: GBMinInstance = req.url === '/'?
|
||||
GBServer.globals.minInstances[0]:
|
||||
GBServer.globals.minInstances.filter(p => p.instance.botId === botId)[0];
|
||||
|
||||
if (min && req.originalUrl && prerender && exclude) {
|
||||
const path = Path.join(
|
||||
process.env.PWD,
|
||||
|
@ -285,16 +288,26 @@ export class GBSSR {
|
|||
res.status(200).send(html);
|
||||
return true;
|
||||
} else {
|
||||
|
||||
const path = Path.join(
|
||||
process.env.PWD,
|
||||
GBDeployer.deployFolder,
|
||||
GBMinService.uiPackage,
|
||||
'build',
|
||||
min ? 'index.html' : req.url
|
||||
);
|
||||
|
||||
min ? `index.html` : req.url
|
||||
);
|
||||
if (Fs.existsSync(path)) {
|
||||
res.sendFile(path);
|
||||
if (min){
|
||||
let html = Fs.readFileSync(path, 'utf8');
|
||||
html = html.replace(/\{botId\}/gi, min.botId);
|
||||
html = html.replace(/\{theme\}/gi, min.instance.theme);
|
||||
html = html.replace(/\{title\}/gi, min.instance.title);
|
||||
res.send(html).end();
|
||||
}
|
||||
else
|
||||
{
|
||||
res.sendFile(path);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
GBLogEx.info(min, `HTTP 404: ${req.url}.`);
|
||||
|
|
|
@ -38,11 +38,18 @@
|
|||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
|
||||
<link rel="sylesheet" href="%PUBLIC_URL%/ssr-delay">
|
||||
|
||||
<link rel="stylesheet" type="text/css" href="./css/pragmatismo.css" />
|
||||
<link rel="stylesheet" type="text/css" href="/themes/{theme}/css/ChatPane.css" />
|
||||
<link rel="stylesheet" type="text/css" href="/themes/{theme}/css/Content.css" />
|
||||
<link rel="stylesheet" type="text/css" href="/themes/{theme}/css/Footer.css" />
|
||||
<link rel="stylesheet" type="text/css" href="/themes/{theme}/css/GifPlayer.css" />
|
||||
<link rel="stylesheet" type="text/css" href="/themes/{theme}/css/MediaPlayer.css" />
|
||||
<link rel="stylesheet" type="text/css" href="/themes/{theme}/css/NavBar.css" />
|
||||
<link rel="stylesheet" type="text/css" href="/themes/{theme}/css/App.css" />
|
||||
<link rel="stylesheet" type="text/css" href="/themes/{theme}/css/SideBarMenu.css" />
|
||||
|
||||
<script src="https://cdn.botframework.com/botframework-webchat/latest/webchat.js"></script>
|
||||
<title>General Bots Community Edition | pragmatismo.io</title>
|
||||
<title>{title} - General Bots Community Edition</title>
|
||||
|
||||
<style>
|
||||
.loader {
|
||||
|
|
|
@ -524,20 +524,21 @@ export class KBService implements IGBKBService {
|
|||
|
||||
// In case of code cell, compiles it and associate with the answer.
|
||||
|
||||
if (/TALK\s*\".*\"/.test(answer) || answer.toLowerCase().startsWith ('/basic') ){
|
||||
const code = answer.substr(6);
|
||||
const gbaiName = `${min.instance.botId}.gbai`;
|
||||
const gbdialogName = `${min.instance.botId}.gbdialog`;
|
||||
const scriptName = `tmp${GBAdminService.getRndReadableIdentifier()}.docx`;
|
||||
const localName = Path.join('work', gbaiName, gbdialogName, `${scriptName}`);
|
||||
Fs.writeFileSync(localName, code, { encoding: null });
|
||||
answer = scriptName;
|
||||
answer = GBVMService.normalizeQuotes(answer);
|
||||
const isBasic = answer.toLowerCase().startsWith('/basic');
|
||||
if (/TALK\s*\".*\"/gi.test(answer) || isBasic) {
|
||||
const code = isBasic ? answer.substr(6) : answer;
|
||||
const gbaiName = `${min.instance.botId}.gbai`;
|
||||
const gbdialogName = `${min.instance.botId}.gbdialog`;
|
||||
const scriptName = `tmp${GBAdminService.getRndReadableIdentifier()}.docx`;
|
||||
const localName = Path.join('work', gbaiName, gbdialogName, `${scriptName}`);
|
||||
Fs.writeFileSync(localName, code, { encoding: null });
|
||||
answer = scriptName;
|
||||
|
||||
const vm = new GBVMService();
|
||||
await vm.loadDialog(Path.basename(localName), Path.dirname(localName), min);
|
||||
const vm = new GBVMService();
|
||||
await vm.loadDialog(Path.basename(localName), Path.dirname(localName), min);
|
||||
}
|
||||
|
||||
|
||||
// Now with all the data ready, creates entities in the store.
|
||||
|
||||
const answer1 = {
|
||||
|
@ -729,7 +730,6 @@ export class KBService implements IGBKBService {
|
|||
|
||||
// Everything else is content for that Header.
|
||||
} else if (state === 1) {
|
||||
|
||||
// If next element is null, the tree has been passed, so
|
||||
// finish the append of other elements between the last Header
|
||||
// and the end of the document.
|
||||
|
@ -748,8 +748,7 @@ export class KBService implements IGBKBService {
|
|||
|
||||
state = 0;
|
||||
|
||||
// Otherwise, just append content to insert later.
|
||||
|
||||
// Otherwise, just append content to insert later.
|
||||
} else {
|
||||
value += value;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue