Cloud Web Scripts downloaded to the browser

This commit is contained in:
Luis Fernando Molina committed 2018-05-21 12:31:02 +02:00
1 parent eb2a147c7d
commit c8d1e26abd
4 files changed
+2390 -9

No files matched your search

+163 -7
View File
@@ -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);
}
}
}