From 4ba0a24af32180ec0abbe1b9e9da73ed07dcc0a5 Mon Sep 17 00:00:00 2001 From: Alan Shaw Date: Fri, 28 Sep 2018 23:00:43 +0100 Subject: [PATCH] fix: block.put with non default options (#1600) License: MIT Signed-off-by: Alan Shaw --- package.json | 6 +++--- src/http/api/resources/block.js | 17 +++++------------ test/utils/interface-common-factory.js | 5 +++++ 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index 1582306eb6..84b5e52f8b 100644 --- a/package.json +++ b/package.json @@ -71,7 +71,7 @@ "expose-loader": "~0.7.5", "form-data": "^2.3.2", "hat": "0.0.3", - "interface-ipfs-core": "~0.76.1", + "interface-ipfs-core": "~0.78.0", "ipfsd-ctl": "~0.39.1", "mocha": "^5.2.0", "ncp": "^2.0.0", @@ -111,7 +111,7 @@ "ipfs-block": "~0.7.1", "ipfs-block-service": "~0.14.0", "ipfs-http-response": "~0.1.2", - "ipfs-mfs": "~0.3.0", + "ipfs-mfs": "~0.4.0", "ipfs-multipart": "~0.1.0", "ipfs-repo": "~0.24.0", "ipfs-unixfs": "~0.1.15", @@ -147,7 +147,7 @@ "mkdirp": "~0.5.1", "multiaddr": "^5.0.0", "multiaddr-to-uri": "^4.0.0", - "multibase": "~0.4.0", + "multibase": "~0.5.0", "multihashes": "~0.4.13", "once": "^1.4.0", "path-exists": "^3.0.0", diff --git a/src/http/api/resources/block.js b/src/http/api/resources/block.js index 1bae34fd8d..c439487a98 100644 --- a/src/http/api/resources/block.js +++ b/src/http/api/resources/block.js @@ -2,9 +2,6 @@ const CID = require('cids') const multipart = require('ipfs-multipart') -const Block = require('ipfs-block') -const waterfall = require('async/waterfall') -const multihashing = require('multihashing-async') const Buffer = require('safe-buffer').Buffer const debug = require('debug') const log = debug('jsipfs:http-api:block') @@ -100,15 +97,11 @@ exports.put = { const data = request.pre.args.data const ipfs = request.server.app.ipfs - waterfall([ - (cb) => multihashing(data, 'sha2-256', (err, multihash) => { - if (err) { - return cb(err) - } - cb(null, new Block(data, new CID(multihash))) - }), - (block, cb) => ipfs.block.put(block, cb) - ], (err, block) => { + ipfs.block.put(data, { + mhtype: request.query.mhtype, + format: request.query.format, + version: request.query.version && parseInt(request.query.version) + }, (err, block) => { if (err) { log.error(err) return reply({ diff --git a/test/utils/interface-common-factory.js b/test/utils/interface-common-factory.js index 97ed69b939..e5377fbaac 100644 --- a/test/utils/interface-common-factory.js +++ b/test/utils/interface-common-factory.js @@ -3,6 +3,7 @@ const each = require('async/each') const IPFSFactory = require('ipfsd-ctl') +const IpfsApi = require('ipfs-api') const IPFS = require('../../src') function createFactory (options) { @@ -11,6 +12,10 @@ function createFactory (options) { options.factoryOptions = options.factoryOptions || { type: 'proc', exec: IPFS } options.spawnOptions = options.spawnOptions || { initOptions: { bits: 512 } } + if (options.factoryOptions.type !== 'proc') { + options.factoryOptions.IpfsApi = options.factoryOptions.IpfsApi || IpfsApi + } + const ipfsFactory = IPFSFactory.create(options.factoryOptions) return function createCommon () {