Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
fix: block.put with non default options (#1600)
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
  • Loading branch information
Alan Shaw authored Sep 28, 2018
1 parent 2d7cfc5 commit 4ba0a24
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
17 changes: 5 additions & 12 deletions src/http/api/resources/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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({
Expand Down
5 changes: 5 additions & 0 deletions test/utils/interface-common-factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 () {
Expand Down

0 comments on commit 4ba0a24

Please sign in to comment.