diff --git a/src/brizo/Brizo.ts b/src/brizo/Brizo.ts index e783245..2f6c09b 100644 --- a/src/brizo/Brizo.ts +++ b/src/brizo/Brizo.ts @@ -131,20 +131,24 @@ export class Brizo extends Instantiable { } private async downloadFile(url: string, destination?: string): Promise { - const response = await WebServiceConnectorProvider - .getConnector() - .get(url) + if (destination) { + const response = await WebServiceConnectorProvider + .getConnector() + .get(url) - const filename = response.headers.get('content-disposition').match(/attachment;filename=(.+)/)[1] + const filename = response.headers.get('content-disposition').match(/attachment;filename=(.+)/)[1] - await new Promise(async (resolve, reject) => { - fs.mkdirSync(destination, {recursive: true}) - const fileStream = fs.createWriteStream(`${destination}${filename}`); - response.body.pipe(fileStream); - response.body.on("error", reject); - fileStream.on("finish", resolve); - }); + await new Promise(async (resolve, reject) => { + fs.mkdirSync(destination, {recursive: true}) + const fileStream = fs.createWriteStream(`${destination}${filename}`); + response.body.pipe(fileStream); + response.body.on("error", reject); + fileStream.on("finish", resolve); + }); - return destination + return destination + } else { + window.open(url, '_blank') + } } } diff --git a/tsconfig.json b/tsconfig.json index 49c939a..f4fac70 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,7 +5,8 @@ "lib": [ "es2017", "es6", - "es7" + "es7", + "DOM" ], "declaration": true, "module": "commonjs", diff --git a/webpack.common.js b/webpack.common.js index 46f5b59..c75d3a3 100644 --- a/webpack.common.js +++ b/webpack.common.js @@ -9,6 +9,9 @@ module.exports = { minimize: true, noEmitOnErrors: true }, + node: { + fs: 'empty', + }, resolve: { extensions: ['.js'], modules: ['node_modules'],