diff --git a/AABrowserAPI/BotCode.js b/AABrowserAPI/BotCode.js
deleted file mode 100644
index c8f2bf687..000000000
--- a/AABrowserAPI/BotCode.js
+++ /dev/null
@@ -1,61 +0,0 @@
-exports.newBotCode = function newBotCode() {
-
- let thisObject = {
- saveBotCode: saveBotCode,
- initialize: initialize
- }
-
- let storage;
-
- return thisObject;
-
- function initialize(pServerConfig) {
-
- const STORAGE = require('../Server/Storage');
- storage = STORAGE.newStorage();
-
- storage.initialize(undefined, pServerConfig);
-
- }
-
- function saveBotCode(pDevTeam, pSource, pRepo, pPath, pSourceCode, callBackFunction) {
-
- let blobText = nodify(pSourceCode.toString());
-
- storage.writeData(pDevTeam + "/" + pSource, pRepo, pPath, blobText, onDataWritten);
-
- function onDataWritten(err) {
-
- if (err.result !== global.DEFAULT_OK_RESPONSE.result) {
-
- console.log("[ERROR] API -> saveBotCode -> Source code file could not be saved. ");
- console.log("[ERROR] API -> saveBotCode -> err.message = " + err.message);
-
- callBackFunction(global.DEFAULT_FAIL_RESPONSE);
- return;
- }
-
- callBackFunction(global.DEFAULT_OK_RESPONSE);
- }
- }
-
- function nodify(pData) {
-
- let start = pData.indexOf('function') + 9;
- let end = pData.indexOf('(') + 0;
-
- let functionName = pData.substring(start, end);
-
- let result = "exports." + functionName + " = " + pData;
-
- result = replaceAll(result, "webRequire", "require");
- result = replaceAll(result, "window", "global");
-
- return result;
-
- function replaceAll(text, search, replacement) {
- return text.replace(new RegExp(search, 'g'), replacement);
- }
- }
-
-}
\ No newline at end of file
diff --git a/AABrowserAPI/TeamSetup.js b/AABrowserAPI/TeamSetup.js
index 5fcd5485b..c7d5bef28 100644
--- a/AABrowserAPI/TeamSetup.js
+++ b/AABrowserAPI/TeamSetup.js
@@ -12,13 +12,10 @@
return thisObject;
- function initialize(pServerConfig) {
+ function initialize(pServerConfig, pStorage) {
- const STORAGE = require('../Server/Storage');
- storage = STORAGE.newStorage();
- masterAppServerURL = pServerConfig.masterAppServerURL;
+ storage = pStorage;
- storage.initialize(undefined, pServerConfig);
}
function newTeam(pTeamCodeName, pTeamDisplayName, pUserName, pBotCodeName, pBotDisplayName, pUserId, callBackFunction) {
diff --git a/Project.njsproj b/Project.njsproj
index 0b11d7487..a5cb51182 100644
--- a/Project.njsproj
+++ b/Project.njsproj
@@ -30,9 +30,6 @@
true
-
- Code
-
Code
@@ -44,6 +41,7 @@
+
@@ -57,13 +55,13 @@
Code
-
+
Code
Code
-
+
Code
@@ -73,7 +71,7 @@
Code
-
+
Code
diff --git a/Scripts/AppPreLoader.js b/Scripts/AppPreLoader.js
index 7faa9c053..e35291b0e 100644
--- a/Scripts/AppPreLoader.js
+++ b/Scripts/AppPreLoader.js
@@ -136,3 +136,39 @@ function callServer(pContentToSend, pPath, callBackFunction) {
}
}
}
+
+
+function getBlobToText(pContainerName, pPath, callBackFunction) {
+
+ let xhttp = new XMLHttpRequest();
+ xhttp.onreadystatechange = function () {
+ if (this.readyState === 4 && this.status === 200) {
+
+ let response = JSON.parse(xhttp.responseText);
+ callBackFunction(response.err, response.text, "");
+
+ }
+ };
+
+ try {
+
+ let request = {
+ conatinerName: pContainerName,
+ path: pPath
+ };
+
+ request = JSON.stringify(request);
+
+ let path = "FileService";
+
+ let blob = new Blob([request], { type: 'text/plain' });
+
+ xhttp.open("POST", path, true);
+ xhttp.send(blob);
+
+ } catch (err) {
+
+ if (ERROR_LOG === true) { console.log(spacePad(MODULE_NAME, 50) + " : " + "[ERROR] getBlobToText -> err.message = " & err.message); }
+
+ }
+}
diff --git a/Server/Storage.js b/Server/AzureStorage.js
similarity index 92%
rename from Server/Storage.js
rename to Server/AzureStorage.js
index f094c0fc7..707187d56 100644
--- a/Server/Storage.js
+++ b/Server/AzureStorage.js
@@ -1,4 +1,4 @@
-exports.newStorage = function newStorage() {
+exports.newAzureStorage = function newAzureStorage() {
let thisObject = {
readData: readData,
@@ -12,13 +12,24 @@
let storageData;
let serverConfig;
+ let Minio = require('minio');
+ let minioClient;
+
return thisObject;
function initialize(pStorageData, pServerConfig) {
storageData = pStorageData;
serverConfig = pServerConfig;
-
+
+ minioClient = new Minio.Client({
+ endPoint: process.env.MINIO_END_POINT,
+ port: JSON.parse(process.env.MINIO_PORT),
+ useSSL: JSON.parse(process.env.MINIO_USE_SSL),
+ accessKey: process.env.MINIO_ACCESS_KEY,
+ secretKey: process.env.MINIO_SECRET_KEY
+ })
+
}
function readData(pOrg, pPath, pFile, saveAtCache, callBackFunction) {
@@ -98,6 +109,27 @@
}
+ /* TEMPORARY CODE TO UPDATE THE MINIO SERVER DURING TRANSITION. */
+
+ try {
+
+ let bucketName = 'aaplatform';
+
+ let textFilename = pOrg + "/" + pPath + "/" + pFile;
+
+ minioClient.putObject(bucketName, textFilename, text, 'text/plain', function (err) {
+ if (err) {
+ console.log("ERROR AT MINIO SERVER PUTTING OBJECT : " + err);
+ return;
+ }
+ console.log(textFilename + ' Successfully uploaded ' + textFilename + ' the MINIO SERVER');
+ })
+
+ } catch (err) {
+ console.log("ERROR UPDATING MINIO SERVER : " + err);
+ }
+
+
callBackFunction(global.DEFAULT_OK_RESPONSE, text);
} catch (err) {
diff --git a/Server/StorageAccessManager.js b/Server/AzureStorageAccessManager.js
similarity index 96%
rename from Server/StorageAccessManager.js
rename to Server/AzureStorageAccessManager.js
index f05ef7d7e..d3c7da237 100644
--- a/Server/StorageAccessManager.js
+++ b/Server/AzureStorageAccessManager.js
@@ -1,4 +1,4 @@
-exports.newStorageAccessManager = function newStorageAccessManager() {
+exports.newAzureStorageAccessManager = function newAzureStorageAccessManager() {
let thisObject = {
getPermission: getPermission,
diff --git a/Server/BotsScripts.js b/Server/BotsScripts.js
index 1f58ade6d..c0fb31b91 100644
--- a/Server/BotsScripts.js
+++ b/Server/BotsScripts.js
@@ -5,15 +5,16 @@
initialize: initialize
}
- const STORAGE = require('../Server/Storage');
- let storage = STORAGE.newStorage();
+ let storage;
let serverConfig;
let storageData;
return thisObject;
- function initialize(pServerConfig, callBackFunction) {
+ function initialize(pServerConfig, pStorage, callBackFunction) {
+
+ storage = pStorage;
let storageData = new Map(); // For backwards compatibility only. Not used.
diff --git a/Server/ConfigReader.js b/Server/ConfigReader.js
index 149506cd8..954aae42b 100644
--- a/Server/ConfigReader.js
+++ b/Server/ConfigReader.js
@@ -8,8 +8,7 @@
const GITHUB = require('../Server/Github');
let github = GITHUB.newGithub();
- const STORAGE = require('../Server/Storage');
- let storage = STORAGE.newStorage();
+ let storage;
let serverConfig;
let storageData;
@@ -18,8 +17,9 @@
return thisObject;
- function initialize(pEcosystem, pEcosystemObject, pStorageData, callBackFunction) {
+ function initialize(pEcosystem, pEcosystemObject, pStorageData, pStorage, callBackFunction) {
+ storage = pStorage;
storageData = pStorageData;
ecosystem = pEcosystem;
ecosystemObject = pEcosystemObject;
diff --git a/Server/MinioStorage.js b/Server/MinioStorage.js
new file mode 100644
index 000000000..5a129d343
--- /dev/null
+++ b/Server/MinioStorage.js
@@ -0,0 +1,463 @@
+exports.newMinioStorage = function newMinioStorage() {
+
+ let thisObject = {
+ readData: readData,
+ writeData: writeData,
+ createContainer: createContainer,
+ deleteContainer: deleteContainer,
+ deleteBlob: deleteBlob,
+ initialize: initialize
+ }
+
+ let storageData;
+ let serverConfig;
+
+ let Minio = require('minio');
+ let minioClient;
+
+ return thisObject;
+
+ function initialize(pStorageData, pServerConfig) {
+
+ storageData = pStorageData;
+ serverConfig = pServerConfig;
+
+ minioClient = new Minio.Client({
+ endPoint: process.env.MINIO_END_POINT,
+ port: JSON.parse(process.env.MINIO_PORT),
+ useSSL: JSON.parse(process.env.MINIO_USE_SSL),
+ accessKey: process.env.MINIO_ACCESS_KEY,
+ secretKey: process.env.MINIO_SECRET_KEY
+ })
+
+ }
+
+ function readData(pOrg, pPath, pFile, saveAtCache, callBackFunction) {
+
+ try {
+
+ 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 -> pPath = " + pPath); }
+ if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> readData -> pFile = " + pFile); }
+
+ let cacheVersion;
+
+ if (storageData !== undefined) {
+
+ cacheVersion = storageData.get(pOrg + '.' + pPath + '.' + pFile);
+ }
+
+ if (cacheVersion !== undefined) {
+
+ if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> readData -> " + pOrg + '.' + pPath + '.' + pFile + " found at cache."); }
+
+ callBackFunction(global.DEFAULT_OK_RESPONSE, cacheVersion);
+
+ } else {
+
+ if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> readData -> " + pOrg + '.' + pPath + '.' + pFile + " 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);
+
+ blobService.getBlobToText('aaplatform', pOrg + "/" + pPath + "/" + pFile, onFileReceived);
+
+
+ function onFileReceived(err, text, response) {
+
+ try {
+
+ 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 -> pPath = " + pPath); }
+ if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> readData -> onFileReceived -> pFile = " + pFile); }
+
+ if (saveAtCache === true) {
+
+ storageData.set(pOrg + '.' + pPath + '.' + pFile, text);
+
+ }
+
+ if (err !== null || text === null) {
+
+ if (CONSOLE_ERROR_LOG === true) { console.log("[ERROR] Storage -> readData -> onFileReceived -> Error Received from Storage Library. "); }
+ if (CONSOLE_ERROR_LOG === true) { console.log("[ERROR] Storage -> readData -> onFileReceived -> err = " + JSON.stringify(err)); }
+ if (CONSOLE_ERROR_LOG === true) { console.log("[ERROR] Storage -> readData -> onFileReceived -> Returning an empty JSON object string. "); }
+
+ callBackFunction(global.DEFAULT_FAIL_RESPONSE);
+ return;
+
+ }
+
+ /* TEMPORARY CODE TO UPDATE THE MINIO SERVER DURING TRANSITION. */
+
+ try {
+
+ let bucketName = 'aaplatform';
+
+ let textFilename = pOrg + "/" + pPath + "/" + pFile;
+
+ minioClient.putObject(bucketName, textFilename, text, 'text/plain', function (err) {
+ if (err) {
+ console.log("ERROR AT MINIO SERVER PUTTING OBJECT : " + err);
+ return;
+ }
+ console.log(textFilename + ' Successfully uploaded ' + textFilename + ' the MINIO SERVER');
+ })
+
+ } catch (err) {
+ console.log("ERROR UPDATING MINIO SERVER : " + err);
+ }
+
+
+ callBackFunction(global.DEFAULT_OK_RESPONSE, text);
+
+ } catch (err) {
+ console.log("[ERROR] Storage -> readData -> onFileReceived -> err.message = " + err.message);
+ callBackFunction(global.DEFAULT_FAIL_RESPONSE);
+ }
+ }
+ }
+
+ } catch (err) {
+ console.log("[ERROR] Storage -> readData -> err.message = " + err.message);
+ callBackFunction(global.DEFAULT_FAIL_RESPONSE);
+ }
+ }
+
+ function writeData(pOrg, pPath, pFile, pFileContent, callBackFunction) {
+
+ try {
+
+ if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> writeData -> Entering function."); }
+ if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> writeData -> pOrg = " + pOrg); }
+ if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> writeData -> pPath = " + pPath); }
+ if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> writeData -> pFile = " + pFile); }
+
+ 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 + "/" + pPath + "/" + pFile;
+ let blobText = pFileContent.toString();
+
+ blobService.createBlockBlobFromText('aaplatform', blobPath, blobText, onFileCreated);
+
+ /* TEMPORARY CODE TO UPDATE THE MINIO SERVER DURING TRANSITION. */
+
+ try {
+
+ let bucketName = 'aaplatform';
+ let text = blobText;
+ let textFilename = blobPath;
+
+ minioClient.putObject(bucketName, textFilename, text, 'text/plain', function (err) {
+ if (err) {
+ console.log("ERROR AT MINIO SERVER PUTTING OBJECT : " + err);
+ return;
+ }
+ console.log(textFilename + ' Successfully uploaded ' + textFilename + ' the MINIO SERVER');
+ })
+
+ } catch (err) {
+ console.log("ERROR UPDATING MINIO SERVER : " + err);
+ }
+
+ function onFileCreated(err, text, response) {
+
+ try {
+
+ if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> writeData -> onFileCreated -> Entering function."); }
+ if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> writeData -> onFileCreated -> err = " + JSON.stringify(err)); }
+ if (LOG_FILE_CONTENT === true) { console.log("[INFO] Storage -> writeData -> onFileCreated -> response = " + JSON.stringify(response)); }
+ if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> writeData -> onFileCreated -> pOrg = " + pOrg); }
+ if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> writeData -> onFileCreated -> pPath = " + pPath); }
+ if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> writeData -> onFileCreated -> pFile = " + pFile); }
+
+ if (err !== null || text === null) {
+
+ if (CONSOLE_ERROR_LOG === true) { console.log("[ERROR] Storage -> writeData -> onFileCreated -> Error Received from Storage Library. "); }
+ if (CONSOLE_ERROR_LOG === true) { console.log("[ERROR] Storage -> writeData -> onFileCreated -> err = " + JSON.stringify(err)); }
+
+ callBackFunction(global.DEFAULT_FAIL_RESPONSE);
+ return;
+
+ }
+
+ callBackFunction(global.DEFAULT_OK_RESPONSE);
+
+ } catch (err) {
+ console.log("[ERROR] Storage -> writeData -> onFileCreated -> err.message = " + err.message);
+ callBackFunction(global.DEFAULT_FAIL_RESPONSE);
+ }
+ }
+
+ } catch (err) {
+ console.log("[ERROR] Storage -> writeData -> err.message = " + err.message);
+ callBackFunction(global.DEFAULT_FAIL_RESPONSE);
+ }
+ }
+
+ function deleteBlob(pOrg, pPath, pFile, callBackFunction) {
+
+ try {
+
+ if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> deleteBlob -> Entering function."); }
+ if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> deleteBlob -> pOrg = " + pOrg); }
+ if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> deleteBlob -> pPath = " + pPath); }
+ if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> deleteBlob -> pFile = " + pFile); }
+
+ 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 + "/" + pPath + "/" + pFile;
+
+ blobService.deleteBlob('aaplatform', blobPath, onBlobDeleted);
+
+ /* TEMPORARY CODE TO UPDATE THE MINIO SERVER DURING TRANSITION. */
+
+ try {
+
+ let bucketName = 'aaplatform';
+ let textFilename = blobPath;
+
+ minioClient.removeObject(bucketName, textFilename, function (err) {
+ if (err) {
+ console.log("ERROR AT MINIO SERVER REMOVING OBJECT : " + textFilename + " " + err);
+ return;
+ }
+ console.log(textFilename + ' Successfully uploaded ' + textFilename + ' the MINIO SERVER');
+ })
+
+ } catch (err) {
+ console.log("ERROR UPDATING MINIO SERVER : " + err);
+ }
+
+ function onBlobDeleted(err, text, response) {
+
+ try {
+
+ if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> deleteBlob -> onBlobDeleted -> Entering function."); }
+ if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> deleteBlob -> onBlobDeleted -> err = " + JSON.stringify(err)); }
+ if (LOG_FILE_CONTENT === true) { console.log("[INFO] Storage -> deleteBlob -> onBlobDeleted -> response = " + JSON.stringify(response)); }
+ if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> deleteBlob -> onBlobDeleted -> pOrg = " + pOrg); }
+ if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> deleteBlob -> onBlobDeleted -> pPath = " + pPath); }
+ if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> deleteBlob -> onBlobDeleted -> pFile = " + pFile); }
+
+ if (err !== null || text === null) {
+
+ if (CONSOLE_ERROR_LOG === true) { console.log("[ERROR] Storage -> deleteBlob -> onBlobDeleted -> Error Received from Storage Library. "); }
+ if (CONSOLE_ERROR_LOG === true) { console.log("[ERROR] Storage -> deleteBlob -> onBlobDeleted -> err = " + JSON.stringify(err)); }
+
+ callBackFunction(global.DEFAULT_FAIL_RESPONSE);
+ return;
+
+ }
+
+ callBackFunction(global.DEFAULT_OK_RESPONSE);
+
+ } catch (err) {
+ console.log("[ERROR] Storage -> deleteBlob -> onBlobDeleted -> err.message = " + err.message);
+ callBackFunction(global.DEFAULT_FAIL_RESPONSE);
+ }
+ }
+
+ } catch (err) {
+ console.log("[ERROR] Storage -> deleteBlob -> err.message = " + err.message);
+ callBackFunction(global.DEFAULT_FAIL_RESPONSE);
+ }
+ }
+
+ function createContainer(pContainerName, callBackFunction) {
+
+ try {
+
+ if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> createContainer -> Entering function."); }
+ if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> createContainer -> pContainerName = " + pContainerName); }
+
+ 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 containerName = pContainerName.toLowerCase();
+
+ blobService.createContainer(containerName, onContainerCreated);
+
+ function onContainerCreated(err) {
+
+ if (err) {
+
+ if (CONSOLE_ERROR_LOG === true) { console.log("[ERROR] Storage -> createContainer -> onContainerCreated -> Error Received from Storage Library. "); }
+ if (CONSOLE_ERROR_LOG === true) { console.log("[ERROR] Storage -> createContainer -> onContainerCreated -> err = " + JSON.stringify(err)); }
+
+
+ /* ContainerAlreadyExists check */
+
+ if (JSON.stringify(err).indexOf("ContainerAlreadyExists") > 0) {
+
+ let err = {
+ resutl: global.CUSTOM_FAIL_RESPONSE.result,
+ message: "ContainerAlreadyExists"
+ };
+
+ callBackFunction(err);
+ return;
+
+ } else {
+
+ callBackFunction(global.DEFAULT_FAIL_RESPONSE);
+ return;
+ }
+
+ callBackFunction(global.DEFAULT_FAIL_RESPONSE);
+ return;
+ }
+
+ callBackFunction(global.DEFAULT_OK_RESPONSE);
+ return;
+ }
+
+ } catch (err) {
+ console.log("[ERROR] Storage -> createContainer -> err.message = " + err.message);
+ callBackFunction(global.DEFAULT_FAIL_RESPONSE);
+ }
+ }
+
+ function deleteContainer(pContainerName, callBackFunction) {
+
+ try {
+
+ if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> deleteContainer -> Entering function."); }
+ if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> deleteContainer -> pContainerName = " + pContainerName); }
+
+ 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 containerName = pContainerName.toLowerCase();
+
+ blobService.deleteContainer(containerName, onContainerDeleted);
+
+ function onContainerDeleted(err) {
+
+ if (err) {
+
+ if (CONSOLE_ERROR_LOG === true) { console.log("[ERROR] Storage -> deleteContainer -> onContainerDeleted -> Error Received from Storage Library. "); }
+ if (CONSOLE_ERROR_LOG === true) { console.log("[ERROR] Storage -> deleteContainer -> onContainerDeleted -> err = " + JSON.stringify(err)); }
+
+
+ /* ContainerAlreadyExists check */
+
+ if (JSON.stringify(err).indexOf("ContainerNotFound") > 0) {
+
+ let err = {
+ resutl: global.CUSTOM_FAIL_RESPONSE.result,
+ message: "ContainerNotFound"
+ };
+
+ callBackFunction(err);
+ return;
+
+ } else {
+
+ callBackFunction(global.DEFAULT_FAIL_RESPONSE);
+ return;
+ }
+
+ callBackFunction(global.DEFAULT_FAIL_RESPONSE);
+ return;
+ }
+
+ callBackFunction(global.DEFAULT_OK_RESPONSE);
+ return;
+ }
+
+ } catch (err) {
+ console.log("[ERROR] Storage -> deleteContainer -> err.message = " + err.message);
+ callBackFunction(global.DEFAULT_FAIL_RESPONSE);
+ }
+ }
+}
\ No newline at end of file
diff --git a/Server/SessionManager.js b/Server/SessionManager.js
index 73a05e60b..0f4183b25 100644
--- a/Server/SessionManager.js
+++ b/Server/SessionManager.js
@@ -9,7 +9,7 @@
return thisObject;
- function initialize(pServerConfig, callBackFunction) {
+ function initialize(pServerConfig, storage, callBackFunction) {
readSessions();
@@ -17,9 +17,6 @@
try {
- const STORAGE = require('../Server/Storage');
- let storage = STORAGE.newStorage();
-
storage.initialize(undefined, pServerConfig);
storage.readData("AdvancedAlgos", "AAPlatform", "open.sessions.json", false, onData);
diff --git a/server.js b/server.js
index 3c712e8c7..581a5ca6a 100644
--- a/server.js
+++ b/server.js
@@ -37,15 +37,7 @@ global.CUSTOM_FAIL_RESPONSE = {
}
/*
-var Minio = require('minio')
-var minioClient = new Minio.Client({
- endPoint: 'niksadvancedalgos.ovh',
- port: 80,
- useSSL: false,
- accessKey: 'luis1234',
- secretKey: '123456789'
-})
const stage = 'textUpload'
const bucketName = 'test-bucket'
@@ -77,8 +69,23 @@ let port = process.env.PORT || 1337
let isHttpServerStarted = false
-const STORAGE = require('./Server/Storage')
-let storage = STORAGE.newStorage()
+const AZURE_STORAGE = require('./Server/AzureStorage')
+const MINIO_STORAGE = require('./Server/MinioStorage')
+
+switch (process.env.STORAGE_PROVIDER) {
+ case 'Azure': {
+ storage = AZURE_STORAGE.newAzureStorage();
+ break;
+ }
+ case 'Minio': {
+ storage = MINIO_STORAGE.newMinioStorage();
+ break;
+ }
+ default: {
+ console.log('[ERROR] server -> Storage Provider not supported -> process.env.STORAGE_PROVIDER = ' + process.env.STORAGE_PROVIDER)
+ return;
+ }
+}
let sessionManager // This module have all authenticated active sessions.
let storageAccessManager // This module manages the SAS for user to access the cloud storage from the browser.
@@ -95,7 +102,7 @@ function initialize () {
const CONFIG_READER = require('./Server/ConfigReader')
let configReader = CONFIG_READER.newConfigReader()
- configReader.initialize(ecosystem, ecosystemObject, storageData, onInitialized)
+ configReader.initialize(ecosystem, ecosystemObject, storageData, storage, onInitialized)
function onInitialized (err, pServerConfig) {
if (err.result !== global.DEFAULT_OK_RESPONSE.result) {
@@ -125,11 +132,11 @@ function initialize () {
const SESSION_MANAGER = require('./Server/SessionManager')
sessionManager = SESSION_MANAGER.newSessionManager()
- sessionManager.initialize(serverConfig, onInitialized)
+ sessionManager.initialize(serverConfig, storage, onInitialized)
function onInitialized () {
- const STORAGE_ACCESS_MANAGER = require('./Server/StorageAccessManager')
- storageAccessManager = STORAGE_ACCESS_MANAGER.newStorageAccessManager()
+ const STORAGE_ACCESS_MANAGER = require('./Server/AzureStorageAccessManager')
+ storageAccessManager = STORAGE_ACCESS_MANAGER.newAzureStorageAccessManager()
storageAccessManager.initialize(serverConfig, onInitialized)
@@ -137,7 +144,7 @@ function initialize () {
const BOT_SCRIPTS = require('./Server/BotsScripts')
botScripts = BOT_SCRIPTS.newBotScripts()
- botScripts.initialize(serverConfig, onInitialized)
+ botScripts.initialize(serverConfig, storage, onInitialized)
function onInitialized () {
startHtttpServer()
@@ -203,7 +210,33 @@ function onBrowserRequest (request, response) {
respondWithFile(filePath, response)
break;
- }
+ }
+
+ case 'FileService':
+ {
+
+ processPost(request, response, onPostReceived)
+
+ function onPostReceived(pData) {
+
+ let request = JSON.parse(pData);
+
+ fileStorage.getFile(container, path, onReady);
+
+ function onReady(err, pFileContent) {
+
+ let response = {
+ err: err,
+ text: pFileContent
+ };
+
+ respondWithContent(JSON.stringify(response));
+ }
+ }
+
+ respondWithFile(filePath, response)
+ break;
+ }
case 'Plotter.js':
{
/*
@@ -475,35 +508,6 @@ function onBrowserRequest (request, response) {
{
switch (requestParameters[2]) {
- case 'saveBotCode': {
- const AABROWSER_API_BOT_CODE = require('./AABrowserAPI/' + 'BotCode')
- let botCode = AABROWSER_API_BOT_CODE.newBotCode()
-
- botCode.initialize(serverConfig)
-
- processPost(request, response, onPostReceived)
-
- function onPostReceived (pData) {
- 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]
- }
- botCode.saveBotCode(devTeam, source, repo, path, pData, onResponse)
-
- function onResponse (err) {
- respondWithContent(JSON.stringify(err), response)
- }
- }
-
- break
- }
-
case "authenticateUser": {
const AABROWSER_API_USER_AUTHENTICATION = require('./AABrowserAPI/' + 'UserAuthentication');
@@ -530,7 +534,7 @@ function onBrowserRequest (request, response) {
const AABROWSER_API_TEAM_SETUP = require('./AABrowserAPI/' + 'TeamSetup');
let teamSetup = AABROWSER_API_TEAM_SETUP.newTeamSetup();
- teamSetup.initialize(serverConfig);
+ teamSetup.initialize(serverConfig, storage);
let devTeamCodeName = decodeURI(requestParameters[3]);
let devTeamDisplayName = decodeURI(requestParameters[4]);
@@ -575,7 +579,7 @@ function onBrowserRequest (request, response) {
const AABROWSER_API_TEAM_SETUP = require('./AABrowserAPI/' + 'TeamSetup')
let teamSetup = AABROWSER_API_TEAM_SETUP.newTeamSetup()
- teamSetup.initialize(serverConfig)
+ teamSetup.initialize(serverConfig, storage)
let devTeamCodeName = decodeURI(requestParameters[3])
let userName = decodeURI(requestParameters[4])