Merge pull request #68 from 67P/update-ipfs-package

Update ipfs package
This commit was merged in pull request #68.
This commit is contained in:
2019-04-03 21:16:22 +02:00
committed by GitHub
3 changed files with 91 additions and 152 deletions

View File

@@ -1,4 +1,4 @@
const ipfsAPI = require('ipfs-api');
const ipfsClient = require('ipfs-http-client');
const multihashes = require('multihashes');
class IPFS {
@@ -7,7 +7,7 @@ class IPFS {
if (!config) {
config = { host: 'localhost', port: '5001', protocol: 'http' };
}
this._ipfsAPI = ipfsAPI(config);
this._ipfsAPI = ipfsClient(config);
this._config = config;
}
@@ -28,7 +28,7 @@ class IPFS {
add(data) {
return this._ipfsAPI
.add(new this._ipfsAPI.Buffer(data))
.add(ipfsClient.Buffer.from(data))
.then((res) => {
return this.decodeHash(res[0].hash);
});
@@ -53,7 +53,7 @@ class IPFS {
}
encodeHash(hashData) {
let digest = this._ipfsAPI.Buffer.from(hashData.hashDigest.slice(2), 'hex');
let digest = ipfsClient.Buffer.from(hashData.hashDigest.slice(2), 'hex');
return multihashes.encode(digest, hashData.hashFunction, hashData.hashSize);
}