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..c8a3bdf8a 100644
--- a/Scripts/AppPreLoader.js
+++ b/Scripts/AppPreLoader.js
@@ -136,3 +136,50 @@ function callServer(pContentToSend, pPath, callBackFunction) {
}
}
}
+
+
+function newFileStorage() {
+
+ thisObject = {
+ getBlobToText: getBlobToText
+ };
+
+ return thisObject;
+
+ 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 87%
rename from Server/Storage.js
rename to Server/AzureStorage.js
index f094c0fc7..8a8a29b24 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) {
@@ -67,7 +78,35 @@
let blobService = storage.createBlobService(connectionString);
- blobService.getBlobToText('aaplatform', pOrg + "/" + pPath + "/" + pFile, onFileReceived);
+ let pParam1 = pOrg;
+ let pParam2 = pPath;
+ let pParam3 = pFile;
+ let container = 'aaplatform';
+ let azurePath = pOrg + "/" + pPath + "/" + pFile;
+
+ let bucketName = 'aaplatform';
+ let textFilename;
+
+ if (pParam1 === undefined) {
+
+ /* This is used when the requests come from the browser, for background compatibility. */
+
+ container = pParam3;
+ azurePath = pParam2;
+
+ bucketName = pParam3;
+ textFilename = pParam2.substring(pParam2.indexOf("/") + 1, pParam2.length);
+
+ } else {
+
+ /* This is used for internal requests within AAWeb, for background compatibility. */
+
+ bucketName = 'aaplatform';
+ textFilename = pParam1 + "/" + pParam2 + "/" + pParam3;
+ }
+
+
+ blobService.getBlobToText(container, azurePath, onFileReceived);
function onFileReceived(err, text, response) {
@@ -98,6 +137,23 @@
}
+ /* TEMPORARY CODE TO UPDATE THE MINIO SERVER DURING TRANSITION. */
+
+ try {
+
+ 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..180bc03cc
--- /dev/null
+++ b/Server/MinioStorage.js
@@ -0,0 +1,351 @@
+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(pParam1, pParam2, pParam3, saveAtCache, callBackFunction) {
+
+ try {
+
+ if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> readData -> Entering function."); }
+ if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> readData -> pParam1 = " + pParam1); }
+ if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> readData -> pParam2 = " + pParam2); }
+ if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> readData -> pParam3 = " + pParam3); }
+
+ let cacheVersion;
+
+ if (storageData !== undefined) {
+
+ cacheVersion = storageData.get(pParam1 + '.' + pParam2 + '.' + pParam3);
+ }
+
+ if (cacheVersion !== undefined) {
+
+ if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> readData -> " + pParam1 + '.' + pParam2 + '.' + pParam3 + " found at cache."); }
+
+ callBackFunction(global.DEFAULT_OK_RESPONSE, cacheVersion);
+
+ } else {
+
+ if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> readData -> " + pParam1 + '.' + pParam2 + '.' + pParam3 + " NOT found at cache."); }
+
+ let bucketName = 'aaplatform';
+ let textFilename;
+
+ if (pParam1 === undefined) {
+
+ /* This is used when the requests come from the browser, for background compatibility. */
+
+ bucketName = pParam3;
+ textFilename = pParam2.substring(pParam2.indexOf("/") + 1, pParam2.length);
+
+ } else {
+
+ /* This is used for internal requests within AAWeb, for background compatibility. */
+
+ bucketName = 'aaplatform';
+ textFilename = pParam1 + "/" + pParam2 + "/" + pParam3;
+ }
+
+ minioClient.getObject(bucketName, textFilename, function (err, dataStream) {
+ let data = '';
+
+ if (err) {
+ onFileReceived(err, null, "Error retrieving file " + textFilename + " from bucket " + bucketName);
+ return
+ }
+ dataStream.on('data', function (chunk) {
+ data += chunk
+ })
+ dataStream.on('end', function () {
+ onFileReceived(null, data, "Data retrieved.");
+ })
+ dataStream.on('error', function (err) {
+ onFileReceived(err, null, "Error on data stream while retrieving file " + textFilename + " from bucket " + bucketName);
+ })
+ })
+
+ 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 -> pParam1 = " + pParam1); }
+ if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> readData -> onFileReceived -> pParam2 = " + pParam2); }
+ if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> readData -> onFileReceived -> pParam3 = " + pParam3); }
+
+ if (saveAtCache === true) {
+
+ storageData.set(pParam1 + '.' + pParam2 + '.' + pParam3, 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. "); }
+
+ if (err.code === 'NoSuchKey') {
+
+ let customErr = {
+ result: GLOBAL.CUSTOM_FAIL_RESPONSE.result,
+ message: 'FileNotFound',
+ code: 'FileNotFound'
+ }
+
+ callBackFunction(customErr);
+ return;
+ }
+
+ callBackFunction(global.DEFAULT_FAIL_RESPONSE);
+ return;
+
+ }
+
+ 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(pParam1, pParam2, pParam3, pFileContent, callBackFunction) {
+
+ try {
+
+ if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> writeData -> Entering function."); }
+ if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> writeData -> pParam1 = " + pParam1); }
+ if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> writeData -> pParam2 = " + pParam2); }
+ if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> writeData -> pParam3 = " + pParam3); }
+
+ let bucketName = 'aaplatform';
+ let text = pFileContent.toString();
+ let textFilename = pParam1 + "/" + pParam2 + "/" + pParam3;
+
+ minioClient.putObject(bucketName, textFilename, text, 'text/plain', onFileCreated)
+
+ 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 -> pParam1 = " + pParam1); }
+ if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> writeData -> onFileCreated -> pParam2 = " + pParam2); }
+ if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> writeData -> onFileCreated -> pParam3 = " + pParam3); }
+
+ 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(pParam1, pParam2, pParam3, callBackFunction) {
+
+ try {
+
+ if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> deleteBlob -> Entering function."); }
+ if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> deleteBlob -> pParam1 = " + pParam1); }
+ if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> deleteBlob -> pParam2 = " + pParam2); }
+ if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> deleteBlob -> pParam3 = " + pParam3); }
+
+ let bucketName = 'aaplatform';
+ let textFilename = pParam1 + "/" + pParam2 + "/" + pParam3;
+
+ minioClient.removeObject(bucketName, textFilename, onBlobDeleted)
+
+ 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 -> pParam1 = " + pParam1); }
+ if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> deleteBlob -> onBlobDeleted -> pParam2 = " + pParam2); }
+ if (CONSOLE_LOG === true) { console.log("[INFO] Storage -> deleteBlob -> onBlobDeleted -> pParam3 = " + pParam3); }
+
+ 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 containerName = pContainerName.toLowerCase();
+
+ minioClient.makeBucket(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 containerName = pContainerName.toLowerCase();
+
+ minioClient.removeBucket(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..675653a59 100644
--- a/server.js
+++ b/server.js
@@ -36,34 +36,6 @@ global.CUSTOM_FAIL_RESPONSE = {
message: 'Custom Message'
}
-/*
-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'
-const textFilename = 'test.json'
-/*
-if (stage === 'textUpload') {
- var str = 'some string you want to save'
- minioClient.putObject(bucketName, textFilename, str, 'text/plain', function (e) {
- if (e) {
- return console.log(e)
- }
- console.log('Successfully uploaded the string')
- })
-}
-
-
-return
-*/
let storageData = new Map()
let botScripts // This module is the one which grabs user bots scrips from the storage, and browserifys them.
@@ -77,8 +49,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 +82,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 +112,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 +124,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 +190,32 @@ function onBrowserRequest (request, response) {
respondWithFile(filePath, response)
break;
- }
+ }
+
+ case 'FileService':
+ {
+
+ processPost(request, response, onPostReceived)
+
+ function onPostReceived(pData) {
+
+ let request = JSON.parse(pData);
+
+ storage.readData(undefined, request.path, request.conatinerName, false, onReady)
+
+ function onReady(err, pFileContent) {
+
+ let responseToClient = {
+ err: err,
+ text: pFileContent
+ };
+
+ respondWithContent(JSON.stringify(responseToClient), response);
+ }
+ }
+
+ break;
+ }
case 'Plotter.js':
{
/*
@@ -475,35 +487,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 +513,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 +558,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])