Server Side Code Reorganized
This commit is contained in:
1 parent
9d5c893de5
commit
2a8f29b3ec
8 files changed
+1198
-1066
No files matched your search
@@ -0,0 +1,102 @@
|
||||
exports.newStorage = function newStorage() {
|
||||
|
||||
let thisObject = {
|
||||
getStorageData: getStorageData,
|
||||
initialize: initialize
|
||||
}
|
||||
|
||||
let storageData;
|
||||
let serverConfig;
|
||||
|
||||
return thisObject;
|
||||
|
||||
function initialize(pStorageData, pServerConfig) {
|
||||
|
||||
storageData = pStorageData;
|
||||
serverConfig = pServerConfig;
|
||||
|
||||
}
|
||||
|
||||
function getStorageData(pOrg, pRepo, pPath, callBackFunction) {
|
||||
|
||||
try {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] getStorageData -> Entering function."); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] getStorageData -> pOrg = " + pOrg); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] getStorageData -> pRepo = " + pRepo); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] getStorageData -> pPath = " + pPath); }
|
||||
|
||||
let cacheVersion = storageData.get(pOrg + '.' + pRepo + '.' + pPath)
|
||||
|
||||
if (cacheVersion !== undefined) {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] getStorageData -> " + pOrg + '.' + pRepo + '.' + pPath + " found at cache."); }
|
||||
|
||||
callBackFunction(cacheVersion);
|
||||
|
||||
} else {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] getStorageData -> " + 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);
|
||||
|
||||
blobService.getBlobToText('aaplatform', pOrg + "/" + pRepo + "/" + pPath, onFileReceived);
|
||||
|
||||
|
||||
function onFileReceived(err, text, response) {
|
||||
|
||||
try {
|
||||
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] getStorageData -> onFileReceived -> Entering function."); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] getStorageData -> onFileReceived -> err = " + JSON.stringify(err)); }
|
||||
if (LOG_FILE_CONTENT === true) { console.log("[INFO] getStorageData -> onFileReceived -> response = " + JSON.stringify(response)); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] getStorageData -> onFileReceived -> pOrg = " + pOrg); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] getStorageData -> onFileReceived -> pRepo = " + pRepo); }
|
||||
if (CONSOLE_LOG === true) { console.log("[INFO] getStorageData -> onFileReceived -> pPath = " + pPath); }
|
||||
|
||||
storageData.set(pOrg + '.' + pRepo + '.' + pPath, text);
|
||||
|
||||
if (err !== null || text === null) {
|
||||
|
||||
console.log("[ERROR] getStorageData -> onFileReceived -> Error Received from Storage Library. ");
|
||||
console.log("[ERROR] getStorageData -> onFileReceived -> err = " + JSON.stringify(err));
|
||||
console.log("[ERROR] getStorageData -> onFileReceived -> Returning an empty JSON object string. ");
|
||||
|
||||
callBackFunction("{}");
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
callBackFunction(text);
|
||||
|
||||
} catch (err) {
|
||||
console.log("[ERROR] getStorageData -> onFileReceived -> err.message = " + err.message);
|
||||
callBackFunction("{}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch (err) {
|
||||
console.log("[ERROR] getStorageData -> err.message = " + err.message);
|
||||
callBackFunction("{}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user