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:
parent
9a252d7731
commit
dde934543c
@ -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')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,8 @@
|
||||
"lib": [
|
||||
"es2017",
|
||||
"es6",
|
||||
"es7"
|
||||
"es7",
|
||||
"DOM"
|
||||
],
|
||||
"declaration": true,
|
||||
"module": "commonjs",
|
||||
|
@ -9,6 +9,9 @@ module.exports = {
|
||||
minimize: true,
|
||||
noEmitOnErrors: true
|
||||
},
|
||||
node: {
|
||||
fs: 'empty',
|
||||
},
|
||||
resolve: {
|
||||
extensions: ['.js'],
|
||||
modules: ['node_modules'],
|
||||
|
Loading…
Reference in New Issue
Block a user