Reads and writes bot scripts at members area.
This commit is contained in:
1 parent
ab20eb9744
commit
acf385bc3c
8 files changed
+101
-174
No files matched your search
+32
-132
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user