1
0
mirror of https://github.com/oceanprotocol/ocean.js.git synced 2024-11-26 20:39:05 +01:00

fix download for large files (#537)

* fix dl

Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro>

* remove console

Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro>

* fix download for compute

Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro>

* fix test

Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro>

* fix test

Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro>

* fix test

Signed-off-by: mihaisc <mihai.scarlat@smartcontrol.ro>
This commit is contained in:
mihaisc 2021-01-12 22:06:16 +02:00 committed by GitHub
parent eff37c2869
commit a21a71ce92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View File

@ -2,6 +2,7 @@ import { BodyInit, RequestInit, Response } from 'node-fetch'
import fs from 'fs'
import { Logger } from '../../utils'
import save from 'save-file'
// import { createWriteStream } from 'streamsaver'
// eslint-disable-next-line @typescript-eslint/no-var-requires
const fetch = require('node-fetch')
@ -101,6 +102,13 @@ export class WebServiceConnector {
}
}
public async downloadFileBrowser(url: string): Promise<void> {
const anchor = document.createElement('a')
anchor.download = ''
anchor.href = url
anchor.click()
}
private async fetch(url: string, opts: RequestInit): Promise<Response> {
const result = await fetch(url, opts)
if (!result.ok) {

View File

@ -147,7 +147,9 @@ export class Provider extends Instantiable {
consumeUrl += `&signature=${signature}`
try {
await this.ocean.utils.fetch.downloadFile(consumeUrl, destination, i)
!destination
? await this.ocean.utils.fetch.downloadFileBrowser(consumeUrl)
: await this.ocean.utils.fetch.downloadFile(consumeUrl, destination, i)
} catch (e) {
this.logger.error('Error consuming assets')
this.logger.error(e)