From 5ed0fcaa23e20a9124994ef8207b12c852449f88 Mon Sep 17 00:00:00 2001 From: Luis Fernando Molina Date: Tue, 21 Apr 2020 14:34:26 +0200 Subject: [PATCH] host and pot implementation --- src/DailyFiles.js | 4 ++-- src/FileCloud.js | 8 ++++---- src/FileSequence.js | 4 ++-- src/FileStorage.js | 17 +++++++++++------ src/MarketFiles.js | 4 ++-- src/SingleFile.js | 4 ++-- 6 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/DailyFiles.js b/src/DailyFiles.js index faf199ce8..356d87f85 100644 --- a/src/DailyFiles.js +++ b/src/DailyFiles.js @@ -45,14 +45,14 @@ function newDailyFiles () { } } - function initialize (pDataMine, pBot, pSession, pProduct, pDataset, pExchange, pMarket, pDatetime, pTimeFrame, callBackFunction) { + function initialize (pDataMine, pBot, pSession, pProduct, pDataset, pExchange, pMarket, pDatetime, pTimeFrame, pHost, pPort, callBackFunction) { try { callBackWhenFileReceived = callBackFunction let exchange = pExchange fileCloud = newFileCloud() - fileCloud.initialize(pBot) + fileCloud.initialize(pBot, pHost, pPort) /* Some Validations */ if (pDataset.code.validTimeFrames === undefined) { diff --git a/src/FileCloud.js b/src/FileCloud.js index 4ee129964..051705797 100644 --- a/src/FileCloud.js +++ b/src/FileCloud.js @@ -17,12 +17,12 @@ function newFileCloud () { initialize: initialize } - let blobService + let fileStorage return thisObject - function initialize (pBot) { - blobService = newFileStorage() + function initialize (pBot, pHost, pPort) { + fileStorage = newFileStorage(pHost, pPort) } function getFile (pDataMine, pBot, pSession, pProduct, pDataset, pExchange, pMarket, pPeriodName, pDatetime, pSequence, pDataRange, callBackFunction) { @@ -121,7 +121,7 @@ function newFileCloud () { if (INFO_LOG === true) { logger.write('[INFO] getFile -> getFileRecursively -> filePath = ' + filePath) } if (INFO_LOG === true) { logger.write('[INFO] getFile -> getFileRecursively -> fileName = ' + fileName) } - blobService.getBlobToText(filePath + '/' + fileName, undefined, onFileReceived) + fileStorage.getFileFromHost(filePath + '/' + fileName, onFileReceived) function onFileReceived (err, text, response) { try { diff --git a/src/FileSequence.js b/src/FileSequence.js index feedf0b32..e9f0f9861 100644 --- a/src/FileSequence.js +++ b/src/FileSequence.js @@ -59,7 +59,7 @@ function newFileSequence () { } } - function initialize (pDataMine, pBot, pSession, pProduct, pDataset, pExchange, pMarket, callBackFunction) { + function initialize (pDataMine, pBot, pSession, pProduct, pDataset, pExchange, pMarket, pHost, pPort, callBackFunction) { try { exchange = pExchange market = pMarket @@ -70,7 +70,7 @@ function newFileSequence () { product = pProduct fileCloud = newFileCloud() - fileCloud.initialize(bot) + fileCloud.initialize(bot, pHost, pPort) callerId = newUniqueId() diff --git a/src/FileStorage.js b/src/FileStorage.js index bdd833546..6bd1d1883 100644 --- a/src/FileStorage.js +++ b/src/FileStorage.js @@ -1,4 +1,4 @@ -function newFileStorage () { +function newFileStorage (host, port) { const MODULE_NAME = 'File Storage' const INFO_LOG = false const logger = newWebDebugLog() @@ -24,20 +24,25 @@ function newFileStorage () { ] let thisObject = { - getBlobToText: getBlobToText + getFileFromHost: getFileFromHost } return thisObject - async function getBlobToText (filePath, host, callBackFunction, pathComplete) { + async function getFileFromHost (filePath, callBackFunction, pathComplete) { try { - if (INFO_LOG === true) { logger.write('[INFO] getBlobToText -> Entering function.') } + if (INFO_LOG === true) { logger.write('[INFO] getFileFromHost -> Entering function.') } let folder = '' if (pathComplete === false || pathComplete === undefined) { folder = 'Storage/' } - callServer(undefined, folder + filePath, (response, fileContent) => { + let url = folder + filePath + if (host !== undefined) { + url = 'http://' + host + ':' + port + '/' + folder + filePath + } + + callServer(undefined, url, (response, fileContent) => { if (response.result === GLOBAL.DEFAULT_OK_RESPONSE.result) { callBackFunction(GLOBAL.DEFAULT_OK_RESPONSE, fileContent) } else { @@ -48,7 +53,7 @@ function newFileStorage () { if (verifyRetry(err.code) && currentRetry < MAX_RETRY) { currentRetry++ if (INFO_LOG === true) { console.log('[INFO] getTextFile -> Retrying connection to the server because received error: ' + err.code + '. Retry #: ' + currentRetry) } - getBlobToText(filePath, host, callBackFunction) + getFileFromHost(filePath, callBackFunction) } else if (err.message === 'Request aborted') { let err = { code: 'The specified key does not exist.' } callBackFunction(err) diff --git a/src/MarketFiles.js b/src/MarketFiles.js index ec1a45ee2..5beb8268e 100644 --- a/src/MarketFiles.js +++ b/src/MarketFiles.js @@ -67,7 +67,7 @@ function newMarketFiles () { } } - function initialize (pDataMine, pBot, pSession, pProduct, pDataset, pExchange, pMarket, callBackFunction) { + function initialize (pDataMine, pBot, pSession, pProduct, pDataset, pExchange, pMarket, pHost, pPort, callBackFunction) { try { exchange = pExchange market = pMarket @@ -78,7 +78,7 @@ function newMarketFiles () { product = pProduct fileCloud = newFileCloud() - fileCloud.initialize(pBot) + fileCloud.initialize(pBot, pHost, pPort) /* Some Validations */ if (dataset.code.validTimeFrames === undefined) { diff --git a/src/SingleFile.js b/src/SingleFile.js index ba9971e6f..50c4858e7 100644 --- a/src/SingleFile.js +++ b/src/SingleFile.js @@ -16,7 +16,7 @@ function newSingleFile () { return thisObject - function initialize (pDataMine, pBot, pSession, pProduct, pDataset, pExchange, pMarket, callBackFunction) { + function initialize (pDataMine, pBot, pSession, pProduct, pDataset, pExchange, pMarket, pHost, pPort, callBackFunction) { try { if (INFO_LOG === true) { logger.write('[INFO] initialize -> Entering function.') } if (INFO_LOG === true) { logger.write('[INFO] initialize -> key = ' + pDataMine.code.codeName + '-' + pBot.code.codeName + '-' + pProduct.code.codeName) } @@ -24,7 +24,7 @@ function newSingleFile () { let exchange = pExchange fileCloud = newFileCloud() - fileCloud.initialize(pBot) + fileCloud.initialize(pBot, pHost, pPort) /* Now we will get the file */