From 1b7f55add5bba52397f77a6837a9b652698289dd Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 9 Apr 2019 15:58:30 +0200 Subject: [PATCH] Storage Gateway final Implementation --- FileStorage | 54 ++++++++++++++++++++++++++++++++++++++++++++++ src/FileStorage.js | 54 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 FileStorage create mode 100644 src/FileStorage.js diff --git a/FileStorage b/FileStorage new file mode 100644 index 000000000..c6c12d006 --- /dev/null +++ b/FileStorage @@ -0,0 +1,54 @@ +function newFileStorage() { + + const MODULE_NAME = 'File Cloud' + const INFO_LOG = false + const ERROR_LOG = true + const logger = newWebDebugLog() + logger.fileName = MODULE_NAME + + thisObject = { + getBlobToText: getBlobToText + }; + + return thisObject; + + function getBlobToText(pContainerName, pPath, callBackFunction) { + + let xhttp = new XMLHttpRequest(); + xhttp.onreadystatechange = function () { + if (this.readyState === 4 && this.status === 200) { + + try { + let response = JSON.parse(xhttp.responseText); + callBackFunction(response.err, response.text, ""); + } catch (err) { + if (ERROR_LOG === true) { console.log(spacePad(MODULE_NAME, 50) + " : " + "[ERROR] AppPreLoader -> getBlobToText -> Invalid JSON received. "); } + if (ERROR_LOG === true) { console.log(spacePad(MODULE_NAME, 50) + " : " + "[ERROR] AppPreLoader -> getBlobToText -> response.text = " & response.text); } + callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE, "", ""); + } + } + }; + + try { + + let request = { + conatinerName: pContainerName, + path: pPath + }; + + request = JSON.stringify(request); + + let path = "FileService"; + + let blob = new Blob([request], { type: 'text/plain' }); + + xhttp.open("GET", path, true); + xhttp.send(blob); + + } catch (err) { + + if (ERROR_LOG === true) { console.log(spacePad(MODULE_NAME, 50) + " : " + "[ERROR] getBlobToText -> err.message = " & err.message); } + + } + } +} \ No newline at end of file diff --git a/src/FileStorage.js b/src/FileStorage.js new file mode 100644 index 000000000..85bad1b01 --- /dev/null +++ b/src/FileStorage.js @@ -0,0 +1,54 @@ +function newFileStorage() { + + const MODULE_NAME = 'File Cloud' + const INFO_LOG = false + const ERROR_LOG = true + const logger = newWebDebugLog() + logger.fileName = MODULE_NAME + + thisObject = { + getBlobToText: getBlobToText + }; + + return thisObject; + + function getBlobToText(pContainerName, pPath, callBackFunction) { + + try { + if (INFO_LOG === true) { logger.write('[INFO] getBlobToText -> Entering function.') } + + let xhttp = new XMLHttpRequest(); + xhttp.onreadystatechange = function () { + if (this.readyState === 4 && this.status === 200) { + + try { + let response = JSON.parse(xhttp.responseText); + callBackFunction(response.err, response.text, ""); + } catch (err) { + if (ERROR_LOG === true) { console.log(spacePad(MODULE_NAME, 50) + " : " + "[ERROR] AppPreLoader -> getBlobToText -> Invalid JSON received. "); } + if (ERROR_LOG === true) { console.log(spacePad(MODULE_NAME, 50) + " : " + "[ERROR] AppPreLoader -> getBlobToText -> response.text = " & response.text); } + callBackFunction(GLOBAL.DEFAULT_FAIL_RESPONSE, "", ""); + } + } + }; + + + let request = { + conatinerName: pContainerName, + path: pPath + }; + + request = JSON.stringify(request); + + let path = window.canvasApp.urlPrefix + "FileService"; + + let blob = new Blob([request], { type: 'text/plain' }); + + xhttp.open("POST", path, true); + xhttp.send(blob); + + } catch (err) { + if (ERROR_LOG === true) { logger.write('[ERROR] getBlobToText -> err = ' + err) } + } + } +} \ No newline at end of file