1
0
mirror of https://github.com/oceanprotocol-archive/squid-js.git synced 2024-02-02 15:31:51 +01:00

Add consume support for browsers.

This commit is contained in:
Pedro Gutiérrez 2019-04-08 16:09:35 +02:00 committed by Pedro Gutiérrez
parent 9a252d7731
commit dde934543c
3 changed files with 21 additions and 13 deletions

View File

@ -131,20 +131,24 @@ export class Brizo extends Instantiable {
}
private async downloadFile(url: string, destination?: string): Promise<string> {
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')
}
}
}

View File

@ -5,7 +5,8 @@
"lib": [
"es2017",
"es6",
"es7"
"es7",
"DOM"
],
"declaration": true,
"module": "commonjs",

View File

@ -9,6 +9,9 @@ module.exports = {
minimize: true,
noEmitOnErrors: true
},
node: {
fs: 'empty',
},
resolve: {
extensions: ['.js'],
modules: ['node_modules'],