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

fix saving downloaded file.

This commit is contained in:
ssallam 2018-12-10 00:15:40 +01:00
parent 5a1016d1fb
commit 4f05e3f455
4 changed files with 21 additions and 12 deletions

View File

@ -57,7 +57,6 @@
"eth-crypto": "^1.2.7", "eth-crypto": "^1.2.7",
"eth-ecies": "^1.0.3", "eth-ecies": "^1.0.3",
"ethereumjs-util": "^6.0.0", "ethereumjs-util": "^6.0.0",
"file-saver": "^2.0.0",
"jsonwebtoken": "^8.4.0", "jsonwebtoken": "^8.4.0",
"node-fetch": "^2.3.0", "node-fetch": "^2.3.0",
"uuid": "^3.3.2", "uuid": "^3.3.2",

View File

@ -8,7 +8,7 @@ import * as config from "./config.json"
(async () => { (async () => {
const ocean: Ocean = await Ocean.getInstance(config) const ocean: Ocean = await Ocean.getInstance(config)
const publisher: Account = (await ocean.getAccounts())[0] const publisher: Account = (await ocean.getAccounts())[1]
const consumer: Account = (await ocean.getAccounts())[1] const consumer: Account = (await ocean.getAccounts())[1]
const metaData = new MetaData({ const metaData = new MetaData({

View File

@ -1,10 +1,10 @@
{ {
"nodeUri": "http://localhost:8545", "nodeUri": "http://localhost:8545",
"aquariusUri": "http://localhost:5000", "aquariusUri": "http://172.15.0.15:5000",
"brizoUri": "http://localhost:8030", "brizoUri": "http://172.15.0.17:8030",
"parityUri": "http://localhost:8545", "parityUri": "http://localhost:8545",
"secretStoreUri": "http://localhost:12001", "secretStoreUri": "http://localhost:12001",
"threshold": 0, "threshold": 0,
"password": "secret", "password": "node0",
"address": "0xa99d43d86a0758d5632313b8fa3972b6088a21bb" "address": "0x00bd138abd70e2f00903268f3db08f2d25677c9e"
} }

View File

@ -24,7 +24,7 @@ import ServiceAgreement from "./ServiceAgreements/ServiceAgreement"
import ServiceAgreementTemplate from "./ServiceAgreements/ServiceAgreementTemplate" import ServiceAgreementTemplate from "./ServiceAgreements/ServiceAgreementTemplate"
import Access from "./ServiceAgreements/Templates/Access" import Access from "./ServiceAgreements/Templates/Access"
import { saveAs } from "file-saver" import * as fs from "fs"
import EventListener from "../keeper/EventListener" import EventListener from "../keeper/EventListener"
import WebServiceConnectorProvider from "../utils/WebServiceConnectorProvider" import WebServiceConnectorProvider from "../utils/WebServiceConnectorProvider"
@ -206,13 +206,23 @@ export default class Ocean {
url = url + `&consumerAddress=${consumer.getId()}` url = url + `&consumerAddress=${consumer.getId()}`
Logger.log("Fetching asset from: ", url) Logger.log("Fetching asset from: ", url)
const response: any = await webConnector.get(url) const response: any = await webConnector.get(url)
const blob: object = await response.blob() const buffer: Buffer = await response.buffer()
// Logger.log("response: ", response.headers, response)
const parts: string[] = cUrl.split("/") const parts: string[] = cUrl.split("/")
const filename: string = parts[parts.length - 1] const filename: string = parts[parts.length - 1]
Logger.log("got blob: ", filename, blob) Logger.debug(`Got response: filename is ${filename}, url is ${response.url}`)
// :FIXME: this does not save the file, debug and fix fs.open("./downloads/" + filename, "w", (err, fd) => {
saveAs(blob, "./downloads/" + filename) if (err) {
throw Error("error opening file for writing." + err)
}
fs.write(fd, buffer, 0, buffer.length, null, (writeErr) => {
if (err) {
throw Error("error writing file: " + writeErr)
}
fs.close(fd, () => {
Logger.debug("file written.")
})
})
})
Logger.log("saved file to:", "./downloads/" + filename) Logger.log("saved file to:", "./downloads/" + filename)
} }
Logger.log("Done downloading asset files.") Logger.log("Done downloading asset files.")