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) {
|
if (text) {
|
||||||
text = text.replace('¨', '"');
|
text = GBVMService.normalizeQuotes(text);
|
||||||
text = text.replace('“', '"');
|
|
||||||
text = text.replace('”', '"');
|
|
||||||
text = text.replace('‘', "'");
|
|
||||||
text = text.replace('’', "'");
|
|
||||||
}
|
}
|
||||||
resolve(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
|
* Converts General Bots BASIC
|
||||||
*
|
*
|
||||||
|
@ -319,7 +324,14 @@ export class GBVMService extends GBService {
|
||||||
/**
|
/**
|
||||||
* Executes the converted JavaScript from BASIC code inside execution context.
|
* 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
|
// Creates a class DialogKeywords which is the *this* pointer
|
||||||
// in BASIC.
|
// in BASIC.
|
||||||
|
|
||||||
|
@ -331,17 +343,18 @@ export class GBVMService extends GBService {
|
||||||
GBConfigService.get('DEFAULT_CONTENT_LANGUAGE')
|
GBConfigService.get('DEFAULT_CONTENT_LANGUAGE')
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// TODO: https://github.com/GeneralBots/BotServer/issues/217
|
||||||
// Auto-NLP generates BASIC variables related to entities.
|
// Auto-NLP generates BASIC variables related to entities.
|
||||||
|
|
||||||
if (step && step.context.activity['originalText']) {
|
// if (step && step.context.activity['originalText'] && min['nerEngine']) {
|
||||||
const entities = await min['nerEngine'].findEntities(step.context.activity['originalText'], contentLocale);
|
// const entities = await min['nerEngine'].findEntities(step.context.activity['originalText'], contentLocale);
|
||||||
|
|
||||||
for (let i = 0; i < entities.length; i++) {
|
// for (let i = 0; i < entities.length; i++) {
|
||||||
const v = entities[i];
|
// const v = entities[i];
|
||||||
const variableName = `${v.entity}`;
|
// const variableName = `${v.entity}`;
|
||||||
sandbox[variableName] = v.option;
|
// sandbox[variableName] = v.option;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
const botId = min.botId;
|
const botId = min.botId;
|
||||||
const gbdialogPath = urlJoin(process.cwd(), 'work', `${botId}.gbai`, `${botId}.gbdialog`);
|
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.
|
// 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 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) {
|
if (min && req.originalUrl && prerender && exclude) {
|
||||||
const path = Path.join(
|
const path = Path.join(
|
||||||
process.env.PWD,
|
process.env.PWD,
|
||||||
|
@ -285,16 +288,26 @@ export class GBSSR {
|
||||||
res.status(200).send(html);
|
res.status(200).send(html);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
const path = Path.join(
|
const path = Path.join(
|
||||||
process.env.PWD,
|
process.env.PWD,
|
||||||
GBDeployer.deployFolder,
|
GBDeployer.deployFolder,
|
||||||
GBMinService.uiPackage,
|
GBMinService.uiPackage,
|
||||||
'build',
|
'build',
|
||||||
min ? 'index.html' : req.url
|
min ? `index.html` : req.url
|
||||||
);
|
);
|
||||||
|
|
||||||
if (Fs.existsSync(path)) {
|
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;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
GBLogEx.info(min, `HTTP 404: ${req.url}.`);
|
GBLogEx.info(min, `HTTP 404: ${req.url}.`);
|
||||||
|
|
|
@ -38,11 +38,18 @@
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||||
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
|
<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="./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>
|
<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>
|
<style>
|
||||||
.loader {
|
.loader {
|
||||||
|
|
|
@ -524,20 +524,21 @@ export class KBService implements IGBKBService {
|
||||||
|
|
||||||
// In case of code cell, compiles it and associate with the answer.
|
// In case of code cell, compiles it and associate with the answer.
|
||||||
|
|
||||||
if (/TALK\s*\".*\"/.test(answer) || answer.toLowerCase().startsWith ('/basic') ){
|
answer = GBVMService.normalizeQuotes(answer);
|
||||||
const code = answer.substr(6);
|
const isBasic = answer.toLowerCase().startsWith('/basic');
|
||||||
const gbaiName = `${min.instance.botId}.gbai`;
|
if (/TALK\s*\".*\"/gi.test(answer) || isBasic) {
|
||||||
const gbdialogName = `${min.instance.botId}.gbdialog`;
|
const code = isBasic ? answer.substr(6) : answer;
|
||||||
const scriptName = `tmp${GBAdminService.getRndReadableIdentifier()}.docx`;
|
const gbaiName = `${min.instance.botId}.gbai`;
|
||||||
const localName = Path.join('work', gbaiName, gbdialogName, `${scriptName}`);
|
const gbdialogName = `${min.instance.botId}.gbdialog`;
|
||||||
Fs.writeFileSync(localName, code, { encoding: null });
|
const scriptName = `tmp${GBAdminService.getRndReadableIdentifier()}.docx`;
|
||||||
answer = scriptName;
|
const localName = Path.join('work', gbaiName, gbdialogName, `${scriptName}`);
|
||||||
|
Fs.writeFileSync(localName, code, { encoding: null });
|
||||||
|
answer = scriptName;
|
||||||
|
|
||||||
const vm = new GBVMService();
|
const vm = new GBVMService();
|
||||||
await vm.loadDialog(Path.basename(localName), Path.dirname(localName), min);
|
await vm.loadDialog(Path.basename(localName), Path.dirname(localName), min);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Now with all the data ready, creates entities in the store.
|
// Now with all the data ready, creates entities in the store.
|
||||||
|
|
||||||
const answer1 = {
|
const answer1 = {
|
||||||
|
@ -729,7 +730,6 @@ export class KBService implements IGBKBService {
|
||||||
|
|
||||||
// Everything else is content for that Header.
|
// Everything else is content for that Header.
|
||||||
} else if (state === 1) {
|
} else if (state === 1) {
|
||||||
|
|
||||||
// If next element is null, the tree has been passed, so
|
// If next element is null, the tree has been passed, so
|
||||||
// finish the append of other elements between the last Header
|
// finish the append of other elements between the last Header
|
||||||
// and the end of the document.
|
// and the end of the document.
|
||||||
|
@ -748,8 +748,7 @@ export class KBService implements IGBKBService {
|
||||||
|
|
||||||
state = 0;
|
state = 0;
|
||||||
|
|
||||||
// Otherwise, just append content to insert later.
|
// Otherwise, just append content to insert later.
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
value += value;
|
value += value;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue