Cloud Web Scripts downloaded to the browser
This commit is contained in:
1 parent
eb2a147c7d
commit
c8d1e26abd
4 files changed
+2390
-9
No files matched your search
+2145
File diff suppressed because it is too large.
Load diff
+163
-7
@@ -1,5 +1,5 @@
|
||||
exports.newConfigReader = function newConfigReader() {
|
||||
|
||||
exports.newCloudScripts = function newCloudScripts() {
|
||||
|
||||
let thisObject = {
|
||||
loadCloudScripts: loadCloudScripts,
|
||||
initialize: initialize
|
||||
@@ -14,19 +14,22 @@
|
||||
let serverConfig;
|
||||
let githubData;
|
||||
let storageData;
|
||||
let fileSystemData;
|
||||
let ecosystem;
|
||||
let ecosystemObject;
|
||||
|
||||
return thisObject;
|
||||
|
||||
function initialize(pEcosystem, pEcosystemObject, pServerConfig, pGithubData, pStorageData, callBackFunction) {
|
||||
function initialize(pEcosystem, pEcosystemObject, pServerConfig, pGithubData, pStorageData, pFileSystemData, callBackFunction) {
|
||||
|
||||
serverConfig = pServerConfig;
|
||||
githubData = pGithubData;
|
||||
fileSystemData = pFileSystemData;
|
||||
storageData = pStorageData;
|
||||
ecosystem = pEcosystem;
|
||||
ecosystemObject = pEcosystemObject;
|
||||
|
||||
callBackFunction();
|
||||
}
|
||||
|
||||
function loadCloudScripts(callBackfunction) {
|
||||
@@ -59,7 +62,7 @@
|
||||
data = data.trim(); // remove first byte with some encoding.
|
||||
|
||||
dataObject = JSON.parse(data);
|
||||
retrieveScripts();
|
||||
retrieveScripts(dataObject, callBackfunction);
|
||||
}
|
||||
catch (err) {
|
||||
console.log("[ERROR] CloudScripts -> loadCloudScripts -> Cloud -> onDataArrived -> Error = " + err);
|
||||
@@ -78,7 +81,7 @@
|
||||
let fileName = '../AACloud/web.config.json';
|
||||
fs.readFile(fileName, onFileRead);
|
||||
|
||||
function onFileRead(err, file) {
|
||||
function onFileRead(err, pData) {
|
||||
|
||||
try {
|
||||
|
||||
@@ -88,7 +91,7 @@
|
||||
data = data.trim(); // remove first byte with some encoding.
|
||||
|
||||
dataObject = JSON.parse(data);
|
||||
retrieveScripts();
|
||||
retrieveScripts(dataObject, callBackfunction);
|
||||
}
|
||||
catch (err) {
|
||||
console.log("[ERROR] CloudScripts -> loadCloudScripts -> File System -> onFileRead -> File = " + fileName + " Error = " + err);
|
||||
@@ -118,7 +121,7 @@
|
||||
data = data.trim(); // remove first byte with some encoding.
|
||||
|
||||
dataObject = JSON.parse(data);
|
||||
retrieveScripts();
|
||||
retrieveScripts(dataObject, callBackfunction);
|
||||
}
|
||||
catch (err) {
|
||||
console.log("[ERROR] CloudScripts -> loadCloudScripts -> Github -> onDataArrived -> Error = " + err);
|
||||
@@ -133,4 +136,157 @@
|
||||
}
|
||||
}
|
||||
|
||||
function retrieveScripts(pCloudWebConfig, callBackfunction) {
|
||||
|
||||
try {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] CloudScripts -> retrieveScripts -> Entering function."); }
|
||||
|
||||
/*
|
||||
|
||||
Here we go through the webModules Array and bring them all.
|
||||
|
||||
*/
|
||||
|
||||
let modulesRetrieved = 0;
|
||||
|
||||
for (let i = 0; i < pCloudWebConfig.webModules.length; i++) {
|
||||
|
||||
let webModule = pCloudWebConfig.webModules[i].name + '.js';
|
||||
|
||||
switch (serverConfig.configAndPlugins.Location) {
|
||||
|
||||
case 'Cloud': {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] CloudScripts -> retrieveScripts -> Cloud -> Entering Case."); }
|
||||
|
||||
storage.getStorageData('AdvancedAlgos', 'AACloud', webModule, onDataArrived);
|
||||
|
||||
function onDataArrived(pData) {
|
||||
|
||||
try {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] CloudScripts -> retrieveScripts -> Cloud -> onDataArrived -> Entering function."); }
|
||||
|
||||
let data = pData.toString();
|
||||
data = data.trim(); // remove first byte with some encoding.
|
||||
|
||||
data = browserify(data);
|
||||
|
||||
storageData.set(webModule, data);
|
||||
|
||||
modulesRetrieved++;
|
||||
if (modulesRetrieved === pCloudWebConfig.webModules.length) {
|
||||
createHTML(callBackfunction);
|
||||
}
|
||||
|
||||
}
|
||||
catch (err) {
|
||||
console.log("[ERROR] CloudScripts -> retrieveScripts -> Cloud -> onDataArrived -> Error = " + err);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case 'File System': {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] CloudScripts -> retrieveScripts -> File System -> Entering Case."); }
|
||||
|
||||
let fs = require('fs');
|
||||
try {
|
||||
let fileName = '../AACloud/' + webModule;
|
||||
fs.readFile(fileName, onFileRead);
|
||||
|
||||
function onFileRead(err, pData) {
|
||||
|
||||
try {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] CloudScripts -> retrieveScripts -> File System -> onFileRead -> Entering function."); }
|
||||
|
||||
let data = pData.toString();
|
||||
data = data.trim(); // remove first byte with some encoding.
|
||||
|
||||
data = browserify(data);
|
||||
|
||||
fileSystemData.set(webModule, data);
|
||||
|
||||
modulesRetrieved++;
|
||||
if (modulesRetrieved === pCloudWebConfig.webModules.length) {
|
||||
createHTML(callBackfunction);
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
console.log("[ERROR] CloudScripts -> retrieveScripts -> File System -> onFileRead -> File = " + fileName + " Error = " + err);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
console.log("[ERROR] CloudScripts -> retrieveScripts -> File System -> File = " + fileName + " Error = " + err);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case 'Github': {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] CloudScripts -> retrieveScripts -> Github -> Entering Case."); }
|
||||
|
||||
github.getGithubData('AdvancedAlgos', 'AACloud', 'web.config.json', onDataArrived);
|
||||
|
||||
function onDataArrived(pData) {
|
||||
|
||||
try {
|
||||
|
||||
let data = pData.toString();
|
||||
data = data.trim(); // remove first byte with some encoding.
|
||||
|
||||
data = browserify(data);
|
||||
|
||||
githubData.set(webModule, data);
|
||||
|
||||
modulesRetrieved++;
|
||||
if (modulesRetrieved === pCloudWebConfig.webModules.length) {
|
||||
createHTML(callBackfunction);
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
console.log("[ERROR] CloudScripts -> retrieveScripts -> Github -> onDataArrived -> Error = " + err);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function browserify(pData) {
|
||||
|
||||
let result = pData.substring(pData.indexOf('=') + 1);
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
function createHTML(callBackfunction) {
|
||||
|
||||
let links = "";
|
||||
let htmlLine = '' + '\n' + ' <script type="text/javascript" src="Cloud/@module@"></script>'
|
||||
|
||||
for (let i = 0; i < pCloudWebConfig.webModules.length; i++) {
|
||||
|
||||
let webModule = pCloudWebConfig.webModules[i].name + '.js';
|
||||
let htmlLineCopy = htmlLine;
|
||||
let newLink = htmlLineCopy.replace('@module@', webModule);
|
||||
|
||||
links = links + newLink;
|
||||
}
|
||||
|
||||
callBackfunction(links);
|
||||
}
|
||||
|
||||
}
|
||||
catch (err) {
|
||||
console.log("[ERROR] CloudScripts -> retrieveScripts -> Error = " + err);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
<script type="text/javascript" src="DebugLog.js"></script>
|
||||
|
||||
<!--CloudWebScripts-->
|
||||
<!--Plotters-->
|
||||
<!--PlotterPanels-->
|
||||
|
||||
|
||||
@@ -9,6 +9,10 @@ let serverConfig;
|
||||
|
||||
let githubData = new Map;
|
||||
let storageData = new Map;
|
||||
let fileSystemData = new Map;
|
||||
|
||||
let HTMLCloudScripts; // This are the html script tags needed to download the cloud web scripts.
|
||||
|
||||
let ecosystem;
|
||||
let ecosystemObject;
|
||||
|
||||
@@ -34,6 +38,7 @@ function initialize() {
|
||||
|
||||
githubData = new Map;
|
||||
storageData = new Map;
|
||||
fileSystemData = new Map;
|
||||
|
||||
const CONFIG_READER = require('./Server/ConfigReader');
|
||||
let configReader = CONFIG_READER.newConfigReader();
|
||||
@@ -54,8 +59,22 @@ function initialize() {
|
||||
github.initialize(githubData);
|
||||
storage.initialize(storageData, serverConfig)
|
||||
|
||||
startHtttpServer();
|
||||
const CLOUD_SCRIPTS = require('./Server/CloudScripts');
|
||||
let cloudScripts = CLOUD_SCRIPTS.newCloudScripts();
|
||||
|
||||
cloudScripts.initialize(ecosystem, ecosystemObject, serverConfig, githubData, storageData, fileSystemData, onInitialized);
|
||||
|
||||
function onInitialized() {
|
||||
|
||||
cloudScripts.loadCloudScripts(onLoadCompeted);
|
||||
|
||||
function onLoadCompeted(pHTMLCloudScripts) {
|
||||
|
||||
HTMLCloudScripts = pHTMLCloudScripts;
|
||||
startHtttpServer();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -319,6 +338,56 @@ function onBrowserRequest(request, response) {
|
||||
}
|
||||
break;
|
||||
|
||||
case "Cloud": // This means the cloud folder.
|
||||
{
|
||||
|
||||
let map;
|
||||
|
||||
switch (serverConfig.configAndPlugins.Location) {
|
||||
|
||||
case 'Cloud': {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] server -> onBrowserRequest -> readEcosystemConfig -> Cloud -> Entering Case."); }
|
||||
|
||||
map = storageData;
|
||||
break;
|
||||
}
|
||||
|
||||
case 'File System': {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] server -> onBrowserRequest -> readEcosystemConfig -> File System -> Entering Case."); }
|
||||
|
||||
map = fileSystemData;
|
||||
break;
|
||||
}
|
||||
|
||||
case 'Github': {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] server -> onBrowserRequest -> readEcosystemConfig -> Github -> Entering Case."); }
|
||||
|
||||
github.getGithubData(requestParameters[2], requestParameters[3], requestParameters[4], onDataArrived);
|
||||
|
||||
map = githubData;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
let script = map.get(requestParameters[2]);
|
||||
|
||||
if (script !== undefined) {
|
||||
|
||||
respondWithContent(script, response);
|
||||
|
||||
} else {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[WARN] server -> onBrowserRequest -> readEcosystemConfig -> Script Not Found."); }
|
||||
if (CONSOLE_LOG === true) { console.log("[WARN] server -> onBrowserRequest -> readEcosystemConfig -> requestParameters[2] = " + requestParameters[2]); }
|
||||
|
||||
respondWithContent("", response);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case "Plotters": // This means the plotter folder, not to be confused with the Plotters script!
|
||||
{
|
||||
|
||||
@@ -465,9 +534,20 @@ function onBrowserRequest(request, response) {
|
||||
|
||||
let fileContent = file.toString();
|
||||
|
||||
addCloudWebScripts();
|
||||
addPlotters();
|
||||
addImages();
|
||||
|
||||
function addCloudWebScripts() {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] server -> onBrowserRequest -> onFileRead -> addCloudWebScripts -> Entering function."); }
|
||||
|
||||
let firstPart = fileContent.substring(0, fileContent.indexOf('<!--CloudWebScripts-->') + 22);
|
||||
let secondPart = fileContent.substring(fileContent.indexOf('<!--CloudWebScripts-->') + 22);
|
||||
|
||||
fileContent = firstPart + HTMLCloudScripts + secondPart;
|
||||
}
|
||||
|
||||
function addPlotters() {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] server -> onBrowserRequest -> onFileRead -> addPlotters -> Entering function."); }
|
||||
@@ -624,7 +704,6 @@ function onBrowserRequest(request, response) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
respondWithContent(fileContent, response);
|
||||
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user