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

Merge pull request #191 from oceanprotocol/bugfix/use-save-file-on-browser

Use save-file to download assets on browser.
This commit is contained in:
Matthias Kretschmann 2019-04-15 16:12:26 +02:00 committed by GitHub
commit f05a98d3d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 118 additions and 27 deletions

117
package-lock.json generated
View File

@ -673,6 +673,11 @@
"integrity": "sha512-Wm6ukoaOGJi/73p/cl2GvLjTI5JM1k/O14isD73YML8StrH/7/lRFgmg8nICZgD3bZZvjwCGxtMOD3wWNAu8cg==",
"dev": true
},
"atob-lite": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/atob-lite/-/atob-lite-2.0.0.tgz",
"integrity": "sha1-D+9a1G8b16hQLGVyfwNn1e5D1pY="
},
"aws-sign2": {
"version": "0.7.0",
"resolved": "https://registry.npmjs.org/aws-sign2/-/aws-sign2-0.7.0.tgz",
@ -1791,6 +1796,11 @@
"create-hmac": "^1.1.4"
}
},
"dtype": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/dtype/-/dtype-2.0.0.tgz",
"integrity": "sha1-zQUjI84GFETs0uj1dI9popvihDQ="
},
"duplexer3": {
"version": "0.1.4",
"resolved": "https://registry.npmjs.org/duplexer3/-/duplexer3-0.1.4.tgz",
@ -2006,6 +2016,7 @@
"resolved": "https://registry.npmjs.org/ethers/-/ethers-4.0.0-beta.1.tgz",
"integrity": "sha512-SoYhktEbLxf+fiux5SfCEwdzWENMvgIbMZD90I62s4GZD9nEjgEWy8ZboI3hck193Vs0bDoTohDISx84f2H2tw==",
"requires": {
"@types/node": "^10.3.2",
"aes-js": "3.0.0",
"bn.js": "^4.4.0",
"elliptic": "6.3.3",
@ -2017,6 +2028,11 @@
"xmlhttprequest": "1.8.0"
},
"dependencies": {
"@types/node": {
"version": "10.14.4",
"resolved": "https://registry.npmjs.org/@types/node/-/node-10.14.4.tgz",
"integrity": "sha512-DT25xX/YgyPKiHFOpNuANIQIVvYEwCWXgK2jYYwqgaMrYE6+tq+DtmMwlD3drl6DJbUwtlIDnn0d7tIn/EbXBg=="
},
"elliptic": {
"version": "6.3.3",
"resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.3.3.tgz",
@ -2333,6 +2349,11 @@
"integrity": "sha512-vNKxJHTEKNThjfrdJwHc7brvM6eVevuO5nTj6ez8ZQ1qbXTvGthucRF7S4vf2cr71QVnT70V34v0S1DyQsti0w==",
"dev": true
},
"file-saver": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/file-saver/-/file-saver-2.0.1.tgz",
"integrity": "sha512-dCB3K7/BvAcUmtmh1DzFdv0eXSVJ9IAFt1mw3XZfAexodNRoE29l3xB2EX4wH2q8m/UTzwzEPq/ArYk98kUkBQ=="
},
"file-type": {
"version": "5.2.0",
"resolved": "https://registry.npmjs.org/file-type/-/file-type-5.2.0.tgz",
@ -2457,6 +2478,14 @@
"is-buffer": "~2.0.3"
}
},
"flatten-vertex-data": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/flatten-vertex-data/-/flatten-vertex-data-1.0.2.tgz",
"integrity": "sha512-BvCBFK2NZqerFTdMDgqfHBwxYWnxeCkwONsw6PvBMcUXqo8U/KDWwmXhqx1x2kLIg7DqIsJfOaJFOmlua3Lxuw==",
"requires": {
"dtype": "^2.0.0"
}
},
"flush-write-stream": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/flush-write-stream/-/flush-write-stream-1.1.1.tgz",
@ -2618,14 +2647,12 @@
"balanced-match": {
"version": "1.0.0",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"brace-expansion": {
"version": "1.1.11",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"balanced-match": "^1.0.0",
"concat-map": "0.0.1"
@ -2640,20 +2667,17 @@
"code-point-at": {
"version": "1.1.0",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"concat-map": {
"version": "0.0.1",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"console-control-strings": {
"version": "1.1.0",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"core-util-is": {
"version": "1.0.2",
@ -2770,8 +2794,7 @@
"inherits": {
"version": "2.0.3",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"ini": {
"version": "1.3.5",
@ -2783,7 +2806,6 @@
"version": "1.0.0",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"number-is-nan": "^1.0.0"
}
@ -2798,7 +2820,6 @@
"version": "3.0.4",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"brace-expansion": "^1.1.7"
}
@ -2910,8 +2931,7 @@
"number-is-nan": {
"version": "1.0.1",
"bundled": true,
"dev": true,
"optional": true
"dev": true
},
"object-assign": {
"version": "4.1.1",
@ -2923,7 +2943,6 @@
"version": "1.4.0",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"wrappy": "1"
}
@ -3045,7 +3064,6 @@
"version": "1.0.2",
"bundled": true,
"dev": true,
"optional": true,
"requires": {
"code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0",
@ -3623,6 +3641,11 @@
}
}
},
"is-base64": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/is-base64/-/is-base64-0.1.0.tgz",
"integrity": "sha512-WRRyllsGXJM7ZN7gPTCCQ/6wNPTRDwiWdPK66l5sJzcU/oOzcIcRRf0Rux8bkpox/1yjt0F6VJRsQOIG2qz5sg=="
},
"is-binary-path": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-1.0.1.tgz",
@ -3632,11 +3655,15 @@
"binary-extensions": "^1.0.0"
}
},
"is-blob": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/is-blob/-/is-blob-1.0.0.tgz",
"integrity": "sha1-o9fZb+HD/wZex84nwsIea6ksGDI="
},
"is-buffer": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/is-buffer/-/is-buffer-2.0.3.tgz",
"integrity": "sha512-U15Q7MXTuZlrbymiz95PJpZxu8IlipAp4dtS3wOdgPXx3mqBnslrWU14kxfHB+Py/+2PVKSr37dMAgM2A4uArw==",
"dev": true
"integrity": "sha512-U15Q7MXTuZlrbymiz95PJpZxu8IlipAp4dtS3wOdgPXx3mqBnslrWU14kxfHB+Py/+2PVKSr37dMAgM2A4uArw=="
},
"is-callable": {
"version": "1.1.4",
@ -6427,6 +6454,19 @@
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
},
"save-file": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/save-file/-/save-file-2.3.1.tgz",
"integrity": "sha512-VOD2Ojb1/kuj0XbvSXzZ5xr4rRSZD8f+HzKWGztXNp93gBQDj3njFt9HMhmLtnwd7q0BjJkzLXqd8M2+PFS1qg==",
"requires": {
"file-saver": "^2.0.0-rc.4",
"is-blob": "^1.0.0",
"is-buffer": "^2.0.0",
"simple-mime": "^0.1.0",
"to-array-buffer": "^3.2.0",
"write": "^1.0.0"
}
},
"schema-utils": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/schema-utils/-/schema-utils-1.0.0.tgz",
@ -6663,6 +6703,11 @@
"simple-concat": "^1.0.0"
}
},
"simple-mime": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/simple-mime/-/simple-mime-0.1.0.tgz",
"integrity": "sha1-lfUXxPRm18/1YacfydqyWW6p7y4="
},
"snapdragon": {
"version": "0.8.2",
"resolved": "https://registry.npmjs.org/snapdragon/-/snapdragon-0.8.2.tgz",
@ -6935,6 +6980,15 @@
"resolved": "https://registry.npmjs.org/strict-uri-encode/-/strict-uri-encode-1.1.0.tgz",
"integrity": "sha1-J5siXfHVgrH1TmWt3UNS4Y+qBxM="
},
"string-to-arraybuffer": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/string-to-arraybuffer/-/string-to-arraybuffer-1.0.2.tgz",
"integrity": "sha512-DaGZidzi93dwjQen5I2osxR9ERS/R7B1PFyufNMnzhj+fmlDQAc1DSDIJVJhgI8Oq221efIMbABUBdPHDRt43Q==",
"requires": {
"atob-lite": "^2.0.0",
"is-base64": "^0.1.0"
}
},
"string-width": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-2.1.1.tgz",
@ -7192,6 +7246,23 @@
"is-negated-glob": "^1.0.0"
}
},
"to-array-buffer": {
"version": "3.2.0",
"resolved": "https://registry.npmjs.org/to-array-buffer/-/to-array-buffer-3.2.0.tgz",
"integrity": "sha512-zN33mwi0gpL+7xW1ITLfJ48CEj6ZQW0ZAP0MU+2W3kEY0PAIncyuxmD4OqkUVhPAbTP7amq9j/iwvZKYS+lzSQ==",
"requires": {
"flatten-vertex-data": "^1.0.2",
"is-blob": "^2.0.1",
"string-to-arraybuffer": "^1.0.0"
},
"dependencies": {
"is-blob": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/is-blob/-/is-blob-2.0.1.tgz",
"integrity": "sha512-SmqVJYMnAeqrKLcwq6TXu1rpAg3yipVlMZIqR5u510rxoOzJGW9GQY6g+WtWkcc44pjbWAuxzZDCkbgf5e6r0Q=="
}
}
},
"to-arraybuffer": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/to-arraybuffer/-/to-arraybuffer-1.0.1.tgz",
@ -8409,6 +8480,14 @@
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8="
},
"write": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/write/-/write-1.0.3.tgz",
"integrity": "sha512-/lg70HAjtkUgWPVZhZcm+T4hkL8Zbtp1nFNOn3lRrxnlv50SRBv7cR7RqR+GMsd3hUXy9hWBo4CHTbFTcOYwig==",
"requires": {
"mkdirp": "^0.5.1"
}
},
"ws": {
"version": "3.3.3",
"resolved": "https://registry.npmjs.org/ws/-/ws-3.3.3.tgz",

View File

@ -65,6 +65,7 @@
"deprecated-decorator": "^0.1.6",
"ethereumjs-util": "^6.1.0",
"node-fetch": "^2.3.0",
"save-file": "^2.3.1",
"uuid": "^3.3.2",
"web3": "1.0.0-beta.37",
"whatwg-url": "^7.0.0"

View File

@ -1,4 +1,6 @@
import * as fs from "fs"
import save = require("save-file")
import { File } from "../ddo/MetaData"
import Account from "../ocean/Account"
import WebServiceConnectorProvider from "../utils/WebServiceConnectorProvider"
@ -131,13 +133,20 @@ export class Brizo extends Instantiable {
}
private async downloadFile(url: string, destination?: string): Promise<string> {
if (destination) {
const response = await WebServiceConnectorProvider
.getConnector()
.get(url)
if (!response.ok) {
throw new Error("Response error.")
}
let filename
try {
filename = response.headers.get("content-disposition").match(/attachment;filename=(.+)/)[1]
} catch {
throw new Error("Response is not containing file name.")
}
const filename = response.headers.get("content-disposition").match(/attachment;filename=(.+)/)[1]
if (destination) {
await new Promise(async (resolve, reject) => {
fs.mkdirSync(destination, {recursive: true})
const fileStream = fs.createWriteStream(`${destination}${filename}`)
@ -148,7 +157,7 @@ export class Brizo extends Instantiable {
return destination
} else {
window.open(url, "_blank")
save(await response.arrayBuffer(), filename)
}
}
}

View File

@ -227,6 +227,8 @@ export class OceanAssets extends Instantiable {
this.logger.log("Locking payment")
const accessGranted = accessCondition.getConditionFulfilledEvent(agreementId).once()
const paid = await oceanAgreements.conditions.lockReward(agreementId, metadata.base.price, consumer)
if (paid) {
@ -238,7 +240,7 @@ export class OceanAssets extends Instantiable {
reject("Error on payment")
}
await accessCondition.getConditionFulfilledEvent(agreementId).once()
await accessGranted
this.logger.log("Access granted")
resolve()