Last active
April 21, 2020 10:46
-
-
Save vijayakumar-psg587/cb7895b8d3272472410fe8696190400c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export async function downloadEnvFiles(env_name): Promise<any> { | |
const LOGGER: pino.Logger = PinoLoggerServiceInstance.getLogger(__filename); | |
return new Promise(async (res, rej) => { | |
// Get the storage | |
const str = GcloudAuthenticationInstance.createGcloudAuthenticationBucket(); | |
try { | |
// get the file list from the storage and the bucket | |
const [files] = await str.bucket(GCLOUD_ENV_STR_BUCKET_NAME).getFiles(); | |
// filter the req file | |
const filteredFile = | |
ENV_NAME_DEV === env_name | |
? _.find(files, (file) => { | |
return file.name.includes(GCLOUD_STORED_FILE_NAME_DEV); | |
}) | |
: _.find(files, (file) => { | |
return file.name.includes(GCLOUD_STORED_FILE_NAME_PROD); | |
}); | |
// send it as a stream | |
res({ | |
status: 'Success', | |
code: 200, | |
error: null, | |
stream: str | |
.bucket(GCLOUD_ENV_STR_BUCKET_NAME) | |
.file(filteredFile.name) | |
.createReadStream(), | |
}); | |
} catch (err) { | |
LOGGER.error('Error in retrieving files from gcloud', err); | |
rej({ status: 'Error', error: err, code: 500 }); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment