Storage Module Upgraded
This commit is contained in:
1 parent
df34480ec6
commit
13d1d2dc49
7 files changed
+110
-105
No files matched your search
+8
-75
@@ -5,19 +5,24 @@
|
||||
initialize: initialize
|
||||
}
|
||||
|
||||
let serverConfig;
|
||||
let storage;
|
||||
|
||||
return thisObject;
|
||||
|
||||
function initialize(pServerConfig) {
|
||||
|
||||
serverConfig = pServerConfig;
|
||||
const STORAGE = require('../Server/Storage');
|
||||
storage = STORAGE.newStorage();
|
||||
|
||||
storage.initialize(undefined, pServerConfig);
|
||||
|
||||
}
|
||||
|
||||
function saveBotCode(pDevTeam, pSource, pRepo, pPath, pSourceCode, callBackFunction) {
|
||||
|
||||
writeData(pDevTeam + "/" + pSource, pRepo, pPath, pSourceCode, onDataWritten);
|
||||
let blobText = nodify(pSourceCode.toString());
|
||||
|
||||
storage.writeData(pDevTeam + "/" + pSource, pRepo, pPath, blobText, onDataWritten);
|
||||
|
||||
function onDataWritten(err) {
|
||||
|
||||
@@ -34,80 +39,8 @@
|
||||
}
|
||||
}
|
||||
|
||||
function writeData(pOrg, pRepo, pPath, pFileContent, callBackFunction) {
|
||||
|
||||
try {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] API -> writeData -> Entering function."); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] API -> writeData -> pOrg = " + pOrg); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] API -> writeData -> pRepo = " + pRepo); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] API -> writeData -> pPath = " + pPath); }
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] API -> writeData -> " + pOrg + '.' + pRepo + '.' + pPath + " NOT found at cache."); }
|
||||
|
||||
let storage = require('azure-storage');
|
||||
let connectionString;
|
||||
|
||||
switch (serverConfig.environment) {
|
||||
|
||||
case "Develop": {
|
||||
|
||||
connectionString = serverConfig.configAndPlugins.Develop.connectionString;
|
||||
break;
|
||||
}
|
||||
|
||||
case "Production": {
|
||||
|
||||
connectionString = serverConfig.configAndPlugins.Production.connectionString;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
let blobService = storage.createBlobService(connectionString);
|
||||
let blobPath = pOrg + "/" + pRepo + "/" + pPath;
|
||||
let blobText = nodify(pFileContent.toString());
|
||||
|
||||
blobService.createBlockBlobFromText('aaplatform', blobPath, blobText, onFileCreated);
|
||||
|
||||
function onFileCreated(err, text, response) {
|
||||
|
||||
try {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] API -> writeData -> onFileCreated -> Entering function."); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] API -> writeData -> onFileCreated -> err = " + JSON.stringify(err)); }
|
||||
if (LOG_FILE_CONTENT === true) { console.log("[INFO] API -> writeData -> onFileCreated -> response = " + JSON.stringify(response)); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] API -> writeData -> onFileCreated -> pOrg = " + pOrg); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] API -> writeData -> onFileCreated -> pRepo = " + pRepo); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] API -> writeData -> onFileCreated -> pPath = " + pPath); }
|
||||
|
||||
if (err !== null || text === null) {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[ERROR] API -> writeData -> onFileCreated -> Error Received from API Library. "); }
|
||||
if (CONSOLE_LOG === true) { console.log("[ERROR] API -> writeData -> onFileCreated -> err = " + JSON.stringify(err)); }
|
||||
if (CONSOLE_LOG === true) { console.log("[ERROR] API -> writeData -> onFileCreated -> Returning an empty JSON object string. "); }
|
||||
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
callBackFunction(global.DEFAULT_OK_RESPONSE);
|
||||
|
||||
} catch (err) {
|
||||
console.log("[ERROR] API -> writeData -> onFileCreated -> err.message = " + err.message);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
console.log("[ERROR] API -> writeData -> err.message = " + err.message);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
function nodify(pData) {
|
||||
|
||||
|
||||
let start = pData.indexOf('function') + 9;
|
||||
let end = pData.indexOf('(') + 0;
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
|
||||
function getScript(pDevTeam, pSource, pRepo, pPath, callBackFunction) {
|
||||
|
||||
storage.getData(pDevTeam + "/" + pSource, pRepo, pPath, false, onDataArrived);
|
||||
storage.readData(pDevTeam + "/" + pSource, pRepo, pPath, false, onDataArrived);
|
||||
|
||||
function onDataArrived(pData) {
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
|
||||
*/
|
||||
|
||||
storage.getData('AdvancedAlgos', 'AACloud', 'web.config.json', true, onDataArrived);
|
||||
storage.readData('AdvancedAlgos', 'AACloud', 'web.config.json', true, onDataArrived);
|
||||
|
||||
function onDataArrived(pData) {
|
||||
|
||||
@@ -84,7 +84,7 @@
|
||||
|
||||
let webModule = pCloudWebConfig.webModules[i].name + '.js';
|
||||
|
||||
storage.getData('AdvancedAlgos', 'AACloud', webModule, true, onDataArrived);
|
||||
storage.readData('AdvancedAlgos', 'AACloud', webModule, true, onDataArrived);
|
||||
|
||||
function onDataArrived(pData) {
|
||||
|
||||
|
||||
@@ -91,7 +91,7 @@
|
||||
|
||||
*/
|
||||
|
||||
storage.getData('AdvancedAlgos', 'AAPlatform', 'ecosystem.json', true, onDataArrived);
|
||||
storage.readData('AdvancedAlgos', 'AAPlatform', 'ecosystem.json', true, onDataArrived);
|
||||
|
||||
function onDataArrived(pData) {
|
||||
|
||||
@@ -145,7 +145,7 @@
|
||||
|
||||
requestsSent++;
|
||||
|
||||
storage.getData(host.codeName + "/" + "competitions", competition.repo, competition.configFile, true, onDataArrived);
|
||||
storage.readData(host.codeName + "/" + "competitions", competition.repo, competition.configFile, true, onDataArrived);
|
||||
|
||||
function onDataArrived(pData) {
|
||||
|
||||
@@ -202,7 +202,7 @@
|
||||
|
||||
requestsSent++;
|
||||
|
||||
storage.getData(host.codeName + "/" + "plotters", plotter.repo, plotter.configFile, true, onDataArrived);
|
||||
storage.readData(host.codeName + "/" + "plotters", plotter.repo, plotter.configFile, true, onDataArrived);
|
||||
|
||||
function onDataArrived(pData) {
|
||||
|
||||
@@ -291,7 +291,7 @@
|
||||
|
||||
requestsSent++;
|
||||
|
||||
storage.getData(devTeam.codeName + "/" + "bots", bot.repo, bot.configFile, true, onDataArrived);
|
||||
storage.readData(devTeam.codeName + "/" + "bots", bot.repo, bot.configFile, true, onDataArrived);
|
||||
|
||||
function onDataArrived(pData) {
|
||||
|
||||
@@ -354,7 +354,7 @@
|
||||
|
||||
requestsSent++;
|
||||
|
||||
storage.getData(devTeam.codeName + "/" + "plotters", plotter.repo, plotter.configFile, true, onDataArrived);
|
||||
storage.readData(devTeam.codeName + "/" + "plotters", plotter.repo, plotter.configFile, true, onDataArrived);
|
||||
|
||||
function onDataArrived(pData) {
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
let storage = STORAGE.newStorage();
|
||||
|
||||
storage.initialize(undefined, pServerConfig);
|
||||
storage.getData("AdvancedAlgos", "AAPlatform", "Open.Sessions.json", false, onData);
|
||||
storage.readData("AdvancedAlgos", "AAPlatform", "Open.Sessions.json", false, onData);
|
||||
|
||||
function onData(pText) {
|
||||
|
||||
|
||||
+91
-19
@@ -1,7 +1,8 @@
|
||||
exports.newStorage = function newStorage() {
|
||||
|
||||
let thisObject = {
|
||||
getData: getData,
|
||||
readData: readData,
|
||||
writeData: writeData,
|
||||
initialize: initialize
|
||||
}
|
||||
|
||||
@@ -17,14 +18,14 @@
|
||||
|
||||
}
|
||||
|
||||
function getData(pOrg, pRepo, pPath, saveAtCache, callBackFunction) {
|
||||
function readData(pOrg, pRepo, pPath, saveAtCache, callBackFunction) {
|
||||
|
||||
try {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> getData -> Entering function."); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> getData -> pOrg = " + pOrg); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> getData -> pRepo = " + pRepo); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> getData -> pPath = " + pPath); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> readData -> Entering function."); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> readData -> pOrg = " + pOrg); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> readData -> pRepo = " + pRepo); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> readData -> pPath = " + pPath); }
|
||||
|
||||
let cacheVersion;
|
||||
|
||||
@@ -35,13 +36,13 @@
|
||||
|
||||
if (cacheVersion !== undefined) {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> getData -> " + pOrg + '.' + pRepo + '.' + pPath + " found at cache."); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> readData -> " + pOrg + '.' + pRepo + '.' + pPath + " found at cache."); }
|
||||
|
||||
callBackFunction(cacheVersion);
|
||||
|
||||
} else {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> getData -> " + pOrg + '.' + pRepo + '.' + pPath + " NOT found at cache."); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> readData -> " + pOrg + '.' + pRepo + '.' + pPath + " NOT found at cache."); }
|
||||
|
||||
let storage = require('azure-storage');
|
||||
let connectionString;
|
||||
@@ -70,12 +71,12 @@
|
||||
|
||||
try {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> getData -> onFileReceived -> Entering function."); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> getData -> onFileReceived -> err = " + JSON.stringify(err)); }
|
||||
if (LOG_FILE_CONTENT === true) { console.log("[INFO] Storage -> getData -> onFileReceived -> response = " + JSON.stringify(response)); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> getData -> onFileReceived -> pOrg = " + pOrg); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> getData -> onFileReceived -> pRepo = " + pRepo); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> getData -> onFileReceived -> pPath = " + pPath); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> readData -> onFileReceived -> Entering function."); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> readData -> onFileReceived -> err = " + JSON.stringify(err)); }
|
||||
if (LOG_FILE_CONTENT === true) { console.log("[INFO] Storage -> readData -> onFileReceived -> response = " + JSON.stringify(response)); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> readData -> onFileReceived -> pOrg = " + pOrg); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> readData -> onFileReceived -> pRepo = " + pRepo); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> readData -> onFileReceived -> pPath = " + pPath); }
|
||||
|
||||
if (saveAtCache === true) {
|
||||
|
||||
@@ -85,9 +86,9 @@
|
||||
|
||||
if (err !== null || text === null) {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[ERROR] Storage -> getData -> onFileReceived -> Error Received from Storage Library. "); }
|
||||
if (CONSOLE_LOG === true) { console.log("[ERROR] Storage -> getData -> onFileReceived -> err = " + JSON.stringify(err)); }
|
||||
if (CONSOLE_LOG === true) { console.log("[ERROR] Storage -> getData -> onFileReceived -> Returning an empty JSON object string. "); }
|
||||
if (CONSOLE_LOG === true) { console.log("[ERROR] Storage -> readData -> onFileReceived -> Error Received from Storage Library. "); }
|
||||
if (CONSOLE_LOG === true) { console.log("[ERROR] Storage -> readData -> onFileReceived -> err = " + JSON.stringify(err)); }
|
||||
if (CONSOLE_LOG === true) { console.log("[ERROR] Storage -> readData -> onFileReceived -> Returning an empty JSON object string. "); }
|
||||
|
||||
callBackFunction("");
|
||||
return;
|
||||
@@ -97,15 +98,86 @@
|
||||
callBackFunction(text);
|
||||
|
||||
} catch (err) {
|
||||
console.log("[ERROR] Storage -> getData -> onFileReceived -> err.message = " + err.message);
|
||||
console.log("[ERROR] Storage -> readData -> onFileReceived -> err.message = " + err.message);
|
||||
callBackFunction("{}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
console.log("[ERROR] Storage -> getData -> err.message = " + err.message);
|
||||
console.log("[ERROR] Storage -> readData -> err.message = " + err.message);
|
||||
callBackFunction("{}");
|
||||
}
|
||||
}
|
||||
|
||||
function writeData(pOrg, pRepo, pPath, pFileContent, callBackFunction) {
|
||||
|
||||
try {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] API -> writeData -> Entering function."); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] API -> writeData -> pOrg = " + pOrg); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] API -> writeData -> pRepo = " + pRepo); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] API -> writeData -> pPath = " + pPath); }
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] API -> writeData -> " + pOrg + '.' + pRepo + '.' + pPath + " NOT found at cache."); }
|
||||
|
||||
let storage = require('azure-storage');
|
||||
let connectionString;
|
||||
|
||||
switch (serverConfig.environment) {
|
||||
|
||||
case "Develop": {
|
||||
|
||||
connectionString = serverConfig.configAndPlugins.Develop.connectionString;
|
||||
break;
|
||||
}
|
||||
|
||||
case "Production": {
|
||||
|
||||
connectionString = serverConfig.configAndPlugins.Production.connectionString;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
let blobService = storage.createBlobService(connectionString);
|
||||
let blobPath = pOrg + "/" + pRepo + "/" + pPath;
|
||||
let blobText = pFileContent.toString();
|
||||
|
||||
blobService.createBlockBlobFromText('aaplatform', blobPath, blobText, onFileCreated);
|
||||
|
||||
function onFileCreated(err, text, response) {
|
||||
|
||||
try {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] API -> writeData -> onFileCreated -> Entering function."); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] API -> writeData -> onFileCreated -> err = " + JSON.stringify(err)); }
|
||||
if (LOG_FILE_CONTENT === true) { console.log("[INFO] API -> writeData -> onFileCreated -> response = " + JSON.stringify(response)); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] API -> writeData -> onFileCreated -> pOrg = " + pOrg); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] API -> writeData -> onFileCreated -> pRepo = " + pRepo); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] API -> writeData -> onFileCreated -> pPath = " + pPath); }
|
||||
|
||||
if (err !== null || text === null) {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[ERROR] API -> writeData -> onFileCreated -> Error Received from API Library. "); }
|
||||
if (CONSOLE_LOG === true) { console.log("[ERROR] API -> writeData -> onFileCreated -> err = " + JSON.stringify(err)); }
|
||||
if (CONSOLE_LOG === true) { console.log("[ERROR] API -> writeData -> onFileCreated -> Returning an empty JSON object string. "); }
|
||||
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
callBackFunction(global.DEFAULT_OK_RESPONSE);
|
||||
|
||||
} catch (err) {
|
||||
console.log("[ERROR] API -> writeData -> onFileCreated -> err.message = " + err.message);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
console.log("[ERROR] API -> writeData -> err.message = " + err.message);
|
||||
callBackFunction(global.DEFAULT_FAIL_RESPONSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -800,7 +800,7 @@ function onBrowserRequest(request, response) {
|
||||
case "Plotters": // This means the plotter folder, not to be confused with the Plotters script!
|
||||
{
|
||||
|
||||
storage.getData(requestParameters[2] + "/" + "plotters", requestParameters[3], requestParameters[4], true, onDataArrived);
|
||||
storage.readData(requestParameters[2] + "/" + "plotters", requestParameters[3], requestParameters[4], true, onDataArrived);
|
||||
|
||||
function onDataArrived(pData) {
|
||||
|
||||
@@ -812,7 +812,7 @@ function onBrowserRequest(request, response) {
|
||||
|
||||
case "PlotterPanels": // This means the PlotterPanels folder, not to be confused with the Plotter Panels scripts!
|
||||
{
|
||||
storage.getData(requestParameters[2] + "/" + "plotters", requestParameters[3], requestParameters[4], true, onDataArrived);
|
||||
storage.readData(requestParameters[2] + "/" + "plotters", requestParameters[3], requestParameters[4], true, onDataArrived);
|
||||
|
||||
function onDataArrived(pData) {
|
||||
|
||||
|
||||
Reference in new issue
Block a user