Reads and writes bot scripts at members area.

This commit is contained in:
Luis Fernando Molina committed 2018-06-02 12:37:38 +02:00
1 parent ab20eb9744
commit acf385bc3c
8 files changed
+101 -174

No files matched your search

+2 -2
View File
@@ -15,9 +15,9 @@
}
function saveBotCode(pSourceCode, callBackFunction) {
function saveBotCode(pDevTeam, pSource, pRepo, pPath, pSourceCode, callBackFunction) {
writeData("AAMasters", "AAMariam-Trading-Bot", "Trading-Process/User.Bot.js", pSourceCode, onDataWritten);
writeData(pDevTeam + "/" + pSource, pRepo, pPath, pSourceCode, onDataWritten);
function onDataWritten(err) {
+2 -2
View File
@@ -148,7 +148,7 @@ function newBreakpointsBar() {
beginMiliseconds = normalizeX(beginMiliseconds);
endMiliseconds = normalizeX(endMiliseconds);
AT_BREAKPOINT = false;
window.AT_BREAKPOINT = false;
for (let miliSeconds = beginMiliseconds; miliSeconds < endMiliseconds; miliSeconds = miliSeconds + timePeriod) {
@@ -202,7 +202,7 @@ function newBreakpointsBar() {
} else {
browserCanvasContext.fillStyle = 'rgba(255, 233, 31, ' + opacity + ')'; /* highlight the current record */
AT_BREAKPOINT = true; // We are hitting a breakpoint!
window.AT_BREAKPOINT = true; // We are hitting a breakpoint!
}
browserCanvasContext.arc(point.x, point.y, radius, 0, Math.PI * 2, true);
+4 -4
View File
@@ -19,13 +19,13 @@
return thisObject;
function downloadBot(pCloudStorage, pProcessConfig, callBackFunction) {
function downloadBot(pCloudStorage, pFilePath, callBackFunction) {
try {
if (INFO_LOG === true) { logger.write("[INFO] downloadBot -> Entering function."); }
let filePath = "Bots" + "/" + bot.devTeam + "/" + bot.repo + "/" + pProcessConfig.name + "/" + "User.Bot.js";
let filePath = "Bots" + "/" + pFilePath + "/" + "User.Bot.js";
downloadModule(filePath, onDownloaded)
@@ -42,13 +42,13 @@
}
}
function downloadCommons(pCloudStorage, callBackFunction) {
function downloadCommons(pCloudStorage, pFilePath, callBackFunction) {
try {
if (INFO_LOG === true) { logger.write("[INFO] downloadCommons -> Entering function."); }
let filePath = "Bots" + "/" + bot.devTeam + "/" + bot.repo + "/" + "Commons.js";
let filePath = "Bots" + "/" + pFilePath + "/" + "Commons.js";
downloadModule(filePath, onDownloaded)
-7
View File
@@ -7,10 +7,6 @@ When running at the clode on NodeJS some things work diffently that at the brows
*/
function webRequire(pModulePath) {
switch (pModulePath) {
@@ -166,6 +162,3 @@ function callServer(pContentToSend, pPath, callBackFunction) {
}
}
+7 -1
View File
@@ -82,7 +82,13 @@ function newCloudVM() {
console.log("Bot code changes detected.");
let path = "AABrowserAPI" + "/"
+ "saveBotCode"
+ "saveBotCode" + "/"
+ window.DEV_TEAM + "/"
+ "members" + "/"
+ window.USER_LOGGED_IN + "/"
+ window.CURRENT_BOT + "/"
+ window.CURRENT_PROCESS + "/"
+ "User.Bot.js"
;
callServer(currentBotCode, path, onServerResponse);
+1 -1
View File
@@ -123,7 +123,7 @@ function convertTimePeriodToName(pTimePeriod) {
}
let cloudVM = newCloudVM();
let AT_BREAKPOINT = false;
window.AT_BREAKPOINT = false;
const DEBUG_START_UP_DELAY = 0 //3000; // This is a waiting time in case there is a need to debug the very first steps of initialization, to be able to hit F12 on time.
const INITIAL_DEFAULT_MARKET = 2; // This is the market that will be shown when loading the site for the first time.
+32 -132
View File
@@ -1,168 +1,68 @@
exports.newBotScripts = function newBotScripts() {
let thisObject = {
loadBotScripts: loadBotScripts,
getScript: getScript,
initialize: initialize
}
const GITHUB = require('../Server/Github');
let github = GITHUB.newGithub();
const STORAGE = require('../Server/Storage');
let storage = STORAGE.newStorage();
let serverConfig;
let storageData;
let ecosystem;
let ecosystemObject;
return thisObject;
function initialize(pEcosystem, pEcosystemObject, pServerConfig, pStorageData, callBackFunction) {
function initialize(pServerConfig, callBackFunction) {
serverConfig = pServerConfig;
storageData = pStorageData;
ecosystem = pEcosystem;
ecosystemObject = pEcosystemObject;
let storageData = new Map(); // For backwards compatibility only. Not used.
storage.initialize(storageData, serverConfig);
storage.initialize(storageData, pServerConfig);
callBackFunction();
}
function loadBotScripts(callBackfunction) {
function getScript(pDevTeam, pSource, pRepo, pPath, callBackFunction) {
try {
storage.getStorageData(pDevTeam + "/" + pSource, pRepo, pPath, onDataArrived);
if (CONSOLE_LOG === true) { console.log("[INFO] BotScripts -> retrieveScripts -> Entering function."); }
function onDataArrived(pData) {
/*
Here we go through the webModules Array and bring them all.
*/
try {
let modulesToBeRetrieved = 0;
let modulesRetrieved = 0;
if (CONSOLE_LOG === true) { console.log("[INFO] BotScripts -> retrieveScripts -> Cloud -> onDataArrived -> Entering function."); }
for (let i = 0; i < ecosystemObject.devTeams.length; i++) {
let data;
let devTeam = ecosystemObject.devTeams[i];
if (pData !== undefined) {
for (let j = 0; j < devTeam.bots.length; j++) {
data = pData.toString();
data = data.trim(); // remove first byte with some encoding.
let bot = devTeam.bots[j];
data = browserify(data);
getCommons(devTeam.codeName, bot.repo, onCommons);
function onCommons() {
for (let k = 0; k < bot.processes.length; k++) {
let process = bot.processes[k];
modulesToBeRetrieved++;
getUserBot(devTeam.codeName, bot.repo, process.name, onUserBot);
function onUserBot() {
modulesRetrieved++;
if (modulesRetrieved === modulesToBeRetrieved) {
callBackfunction();
}
}
}
}
}
callBackFunction(data);
}
function getCommons(pDevTeam, pRepo, callBack) {
let moduleName = "Commons.js";
let key = pDevTeam + "." + pRepo;
let path = pDevTeam + "/" + pRepo;
storage.getStorageData(pDevTeam + "/" + "bots", pRepo, moduleName, onDataArrived);
function onDataArrived(pData) {
try {
if (CONSOLE_LOG === true) { console.log("[INFO] BotScripts -> retrieveScripts -> Cloud -> onDataArrived -> Entering function."); }
if (pData !== undefined) {
let data = pData.toString();
data = data.trim(); // remove first byte with some encoding.
data = browserify(data);
storageData.set(key, data);
}
callBack();
}
catch (err) {
console.log("[ERROR] BotScripts -> retrieveScripts -> Cloud -> onDataArrived -> Error = " + err);
}
}
catch (err) {
console.log("[ERROR] BotScripts -> retrieveScripts -> Cloud -> onDataArrived -> Error = " + err);
}
function getUserBot(pDevTeam, pRepo, pProcess, callBack) {
let moduleName = "User.Bot.js";
let key = pDevTeam + "." + pRepo + "." + pProcess + "/" + moduleName;
let path = pProcess + "/" + moduleName;
storage.getStorageData(pDevTeam + "/" + "bots", pRepo, path, onDataArrived);
function onDataArrived(pData) {
try {
if (CONSOLE_LOG === true) { console.log("[INFO] BotScripts -> retrieveScripts -> Cloud -> onDataArrived -> Entering function."); }
if (pData !== undefined) {
let data = pData.toString();
data = data.trim(); // remove first byte with some encoding.
data = browserify(data);
storageData.set(key, data);
}
callBack();
}
catch (err) {
console.log("[ERROR] BotScripts -> retrieveScripts -> Cloud -> onDataArrived -> Error = " + err);
}
}
}
function browserify(pData) {
let result = pData.substring(pData.indexOf('=') + 2);
result = replaceAll(result, "require", "webRequire");
result = replaceAll(result, "global", "window");
return result;
function replaceAll(text, search, replacement) {
return text.replace(new RegExp(search, 'g'), replacement);
}
}
}
catch (err) {
console.log("[ERROR] BotScripts -> retrieveScripts -> Error = " + err);
}
function browserify(pData) {
let result = pData.substring(pData.indexOf('=') + 2);
result = replaceAll(result, "require", "webRequire");
result = replaceAll(result, "global", "window");
return result;
function replaceAll(text, search, replacement) {
return text.replace(new RegExp(search, 'g'), replacement);
}
}
}
+53 -25
View File
@@ -35,6 +35,7 @@ global.CUSTOM_FAIL_RESPONSE = {
let storageData = new Map;
let HTMLCloudScripts; // This are the html script tags needed to download the cloud web scripts.
let botScripts; // This module is the one which grabs user bots scrips from the storage, and browserifys them.
let ecosystem;
let ecosystemObject;
@@ -95,19 +96,15 @@ function initialize() {
function onInitialized() {
const BOT_SCRIPTS = require('./Server/BotsScripts');
let botScripts = BOT_SCRIPTS.newBotScripts();
botScripts = BOT_SCRIPTS.newBotScripts();
botScripts.initialize(ecosystem, ecosystemObject, serverConfig, storageData, onInitialized);
botScripts.initialize(serverConfig, onInitialized);
function onInitialized() {
botScripts.loadBotScripts(onScriptsLoaded);
HTMLCloudScripts = pHTMLCloudScripts;
startHtttpServer();
function onScriptsLoaded(){
HTMLCloudScripts = pHTMLCloudScripts;
startHtttpServer();
}
}
}
}
@@ -429,7 +426,18 @@ function onBrowserRequest(request, response) {
switch (requestParameters[2]) {
case "saveBotCode": {
api.saveBotCode(pData, onResponse);
let devTeam = requestParameters[3];
let source = requestParameters[4] + "/" + requestParameters[5];
let repo = requestParameters[6];
let path;
if (requestParameters[8] !== undefined) {
path = requestParameters[7] + "/" + requestParameters[8];
} else {
path = requestParameters[7];
}
api.saveBotCode(devTeam, source, repo, path, pData, onResponse);
break;
}
@@ -643,33 +651,53 @@ function onBrowserRequest(request, response) {
case "Bots": // This means the cloud folder.
{
switch (requestParameters[3]) {
let map = storageData;
case 'bots': {
let key;
let devTeam = requestParameters[2];
let source = requestParameters[3];
let repo = requestParameters[4];
let path;
if (requestParameters[5] !== undefined) {
if (requestParameters[6] !== undefined) {
path = requestParameters[5] + "/" + requestParameters[6];
} else {
path = requestParameters[5];
}
key = requestParameters[2] + "." + requestParameters[3] + "." + requestParameters[4] + "/" + requestParameters[5];
botScripts.getScript(devTeam, source, repo, path, onScriptReady)
} else {
break;
}
key = requestParameters[2] + "." + requestParameters[3] + "." + requestParameters[4];
case 'members': {
let devTeam = requestParameters[2];
let source = requestParameters[3] + "/" + requestParameters[4];
let repo = requestParameters[5];
let path;
if (requestParameters[7] !== undefined) {
path = requestParameters[6] + "/" + requestParameters[7];
} else {
path = requestParameters[6];
}
botScripts.getScript(devTeam, source, repo, path, onScriptReady)
break;
}
default : {
if (CONSOLE_LOG === true) { console.log("[ERROR] server -> onBrowserRequest -> Bots -> Invalid Request. "); }
}
}
let script = map.get(key);
function onScriptReady(pScript) {
if (script !== undefined && script !== null) {
respondWithContent(pScript, response);
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 -> key = " + key); }
respondWithContent("", response);
}
}
break;