From bba153740c905e5e95759c4bd9bbb010553afd2e Mon Sep 17 00:00:00 2001 From: Alex Potsides Date: Thu, 17 Oct 2019 11:21:30 +0100 Subject: [PATCH] fix: choose import strategy in ipfs.add (#2541) * fix: choose import strategy in ipfs.add The interface spec says you should pass a `trickle` boolean to `ipfs.add` to get a trickle DAG, this PR makes us actually do that instead of passing `strategy: 'whatever'`. * fix: remove trickle arg before passing to importer --- src/cli/commands/add.js | 2 +- src/core/components/files-regular/add-async-iterator.js | 7 +++++++ src/http/api/resources/files-regular.js | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/cli/commands/add.js b/src/cli/commands/add.js index a76ba3a7f8..3bfe6f9866 100644 --- a/src/cli/commands/add.js +++ b/src/cli/commands/add.js @@ -113,7 +113,7 @@ module.exports = { argv.resolve((async () => { const ipfs = await argv.getIpfs() const options = { - strategy: argv.trickle ? 'trickle' : 'balanced', + trickle: argv.trickle, shardSplitThreshold: argv.enableShardingExperiment ? argv.shardSplitThreshold : Infinity, diff --git a/src/core/components/files-regular/add-async-iterator.js b/src/core/components/files-regular/add-async-iterator.js index c5ab26bb38..e138a1cd66 100644 --- a/src/core/components/files-regular/add-async-iterator.js +++ b/src/core/components/files-regular/add-async-iterator.js @@ -21,6 +21,7 @@ module.exports = function (self) { ? 1000 : Infinity }, options, { + strategy: 'balanced', chunker: chunkerOptions.chunker, chunkerOptions: chunkerOptions.chunkerOptions }) @@ -30,6 +31,12 @@ module.exports = function (self) { opts.cidVersion = 1 } + if (opts.trickle) { + opts.strategy = 'trickle' + } + + delete opts.trickle + let total = 0 const prog = opts.progress || noop diff --git a/src/http/api/resources/files-regular.js b/src/http/api/resources/files-regular.js index 4aadc8f041..d71842b3ac 100644 --- a/src/http/api/resources/files-regular.js +++ b/src/http/api/resources/files-regular.js @@ -219,7 +219,7 @@ exports.add = { wrapWithDirectory: request.query['wrap-with-directory'], pin: request.query.pin, chunker: request.query.chunker, - strategy: request.query.trickle ? 'trickle' : 'balanced', + trickle: request.query.trickle, preload: request.query.preload }) },