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:
parent
eff37c2869
commit
a21a71ce92
@ -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) {
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user